Can Someone Help Please

Reply

Join Date: Oct 2008
Posts: 29
Reputation: Superstar288 is an unknown quantity at this point 
Solved Threads: 0
Superstar288 Superstar288 is offline Offline
Light Poster

Can Someone Help Please

 
0
  #1
Dec 30th, 2008
hey can anyone help me with some work please i have been asked
to:
provide information about the number and total amount of purchases from each suppliers each month, the number of sales and total price for each category of animal each month.

at the moment i have got the information of a supplier order in an arraylist this includes the name of the supplier, price date,and animal. but i really not sure on how to get this information or work it out when when i have got the info all i want to do is print to a jtextarea which i can do.

so any help will be much appericated Thanks
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: Can Someone Help Please

 
0
  #2
Dec 31st, 2008
we don't know how you store the data in that ArrayList, so how can we tell?

let's say that you store your data in there as a object of a type 'Person' which has (among others) a String variable name and a String variable lastName.

  1. int location = // the location of the person in your ArrayList
  2. Person stored = (Person)myList.get(location);
  3. JTextArea tArea = new JTextArea();
  4. String in = stored.getName() + "\n" + stored.getLastName();
  5. tArea.setText(in);

is this what you were looking for?
Last edited by stultuske; Dec 31st, 2008 at 4:27 am. Reason: corrected code-tags
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,566
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 196
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: Can Someone Help Please

 
0
  #3
Dec 31st, 2008
If your class that you're making an ArrayList of is called Supplier, write a toString method in the Supplier class. The toString method should return a String that contains all the information (name, etc) for a Supplier. Then, for each Supplier in the ArrayList, do yourTextArea.append(Supplier.toString())
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 29
Reputation: Superstar288 is an unknown quantity at this point 
Solved Threads: 0
Superstar288 Superstar288 is offline Offline
Light Poster

Re: Can Someone Help Please

 
0
  #4
Dec 31st, 2008
hi thanks for the replies everyone. i have done a to string method to get it to display my information its just i dont know how to calculate the cost of that certain supplier and how many times it has been purchased from. any help with this cause i really am stuck thanks
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 53
quuba quuba is offline Offline
Posting Whiz

Re: Can Someone Help Please

 
0
  #5
Jan 1st, 2009
CONCEPT (paper & pencil)
This is database.
You have a input Record: (supplierName, date, animalName, price).
Now is time to make a model. Only 4 fields. What is relation beetwen them. I started from end. Pair (animalName, price) is inextricably linked.
Animal:
-name
-price
Purchase is relate to date and Animal
Purchase:
-date
-Animal
Supplier have a name and a list of Purchase
Supplier:
-name
-List<Purchase> purchaseList
Who have a list of suppliers ? - Owner.
Owner:
-List<Supplier> supplierList
Four classes are ready
Animal
Purchase
Supplier
Owner
where name is String-type, data is Data-type, price is int or float.
Make a constructors with suitable parameters and initialize Lists.
For all classes write toString() methods.
For example Animal:
  1. public String toString() {
  2. StringBuffer sb = new StringBuffer();
  3. sb.append("Animal:");
  4. sb.append("name=");
  5. sb.append(name);
  6. sb.append(",");
  7. sb.append("price=");
  8. sb.append(price);
  9. sb.append("|");
  10. return sb.toString();
  11. }
For Purchase:
  1. public String toString() {
  2. StringBuffer sb = new StringBuffer();
  3. sb.append("Purchase:");
  4. sb.append("Date=");
  5. sb.append(date);
  6. sb.append(",");
  7. sb.append(animal);
  8. return sb.toString();
  9. }
For Supplier:
  1. public String toString() {
  2. StringBuffer sb = new StringBuffer();
  3. sb.append("Supplier:");
  4. sb.append("name=");
  5. sb.append(name);
  6. sb.append(",");
  7. for (Purchase inner : purchaseList) {
  8. sb.append(inner);
  9. }
  10. return sb.toString();
  11. }
For Owner:
  1. public String toString() {
  2. StringBuffer sb = new StringBuffer();
  3. sb.append("Owner:");
  4. //TODO
  5. return sb.toString();
  6. }
DATABASE FILLING
  1. import java.util.ArrayList;
  2. import java.util.Date;
  3. import java.util.List;
  4.  
  5. public class Superstar {
  6.  
  7. Owner owner;
  8.  
  9. public Superstar() {
  10. owner = new Owner();
  11. String supplierName = "Smith";
  12. Date date = new Date();
  13. String animalName = "dog";
  14. int price = 100;
  15. owner.add(supplierName, date, animalName, price);
  16. date = new Date();
  17. long time = date.getTime() - 8888888888L;
  18. date.setTime(time);
  19. owner.add(supplierName, date, "cow", 1000);
  20. owner.add("Byron", date, "cat", 5);
  21. System.out.println(owner);
  22. //first simple question
  23. int numberOfSales = owner.getNumberOfSales();
  24. System.out.println("numberOfSales=" + numberOfSales);
  25.  
  26. }
  27. public static void main(String[] args) {
  28. new Superstar();
  29. }
  30. }
  1. public class Owner {
  2.  
  3. private List<Supplier> supplierList = new ArrayList<Supplier>();
  4.  
  5. // by name
  6. public Supplier getSupplier(String supplierName) {
  7. for (Supplier inner : supplierList) {
  8. if (inner.getName().equals(supplierName)) {
  9. return inner;
  10. }
  11. }
  12. return (Supplier) null;
  13. }
  14.  
  15. public void add(String supplierName, Date currDate, String animalName, int animalPrice) {
  16. Animal animal = new Animal(animalName, animalPrice);
  17. Purchase purchase = new Purchase(currDate, animal);
  18. // check for supplier
  19. Supplier supplier = getSupplier(supplierName);
  20. if (supplier == null) {
  21. supplier = new Supplier(supplierName, purchase);
  22. // add new suplier to supplierList
  23. supplierList.add(supplier);
  24. } else {
  25. //supplier exist,add
  26. supplier.add(purchase);
  27. }
  28. }
  29.  
  30. @Override
  31. public String toString() {
  32. StringBuffer sb = new StringBuffer();
  33. sb.append("Owner:");
  34. for (Supplier inner : supplierList) {
  35. sb.append("\n");
  36. sb.append(inner);
  37. }
  38. return sb.toString();
  39. }
  40.  
  41. public int getNumberOfSales() {
  42. int numberOfSales = 0;
  43. for (Supplier inner : supplierList) {
  44. numberOfSales += inner.getNumberOfSales();
  45. }
  46. return numberOfSales;
  47. }
  48. }
This proposal of computer program has a "hierarchical" structure in sense that all user questions are directed to owner. Question goes down to structure.
Try implement:
int sumOfPrices = owner.getSumOfPrices();

List<String> supplierNames = owner.getSupplierNames();
List<String> animalNames = owner.getAnimalNames();
List<String> uniqueAnimalNames = owner.getUniqueAnimalNames();
Iterate throught List<Supplier> you can ask owner.getSumOfPrices(supplierName); to obtain List<SupplierPrice> where
SupplierPrice:
-name // String supplierName
-price // int/double sumOfPricesForCurrentSuplier
...
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 29
Reputation: Superstar288 is an unknown quantity at this point 
Solved Threads: 0
Superstar288 Superstar288 is offline Offline
Light Poster

Re: Can Someone Help Please

 
0
  #6
Jan 1st, 2009
wow thanks very much for that i will try and implement this into my program and get it to work. all this is much apperciated and have a happy new year
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC