| | |
Can Someone Help Please
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2008
Posts: 29
Reputation:
Solved Threads: 0
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
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
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.
is this what you were looking for?
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.
Java Syntax (Toggle Plain Text)
int location = // the location of the person in your ArrayList Person stored = (Person)myList.get(location); JTextArea tArea = new JTextArea(); String in = stored.getName() + "\n" + stored.getLastName(); 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
•
•
Join Date: Sep 2008
Posts: 1,597
Reputation:
Solved Threads: 202
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())
•
•
Join Date: Nov 2008
Posts: 332
Reputation:
Solved Threads: 53
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.
Purchase is relate to date and Animal
Supplier have a name and a list of Purchase
Who have a list of suppliers ? - Owner.
Four classes are ready
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:
For Purchase:
For Supplier:
For Owner:
DATABASE FILLING
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
...
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:
-date
-Animal
•
•
•
•
Supplier:
-name
-List<Purchase> purchaseList
•
•
•
•
Owner:
-List<Supplier> supplierList
•
•
•
•
Animal
Purchase
Supplier
Owner
Make a constructors with suitable parameters and initialize Lists.
For all classes write toString() methods.
For example Animal:
java Syntax (Toggle Plain Text)
public String toString() { StringBuffer sb = new StringBuffer(); sb.append("Animal:"); sb.append("name="); sb.append(name); sb.append(","); sb.append("price="); sb.append(price); sb.append("|"); return sb.toString(); }
java Syntax (Toggle Plain Text)
public String toString() { StringBuffer sb = new StringBuffer(); sb.append("Purchase:"); sb.append("Date="); sb.append(date); sb.append(","); sb.append(animal); return sb.toString(); }
java Syntax (Toggle Plain Text)
public String toString() { StringBuffer sb = new StringBuffer(); sb.append("Supplier:"); sb.append("name="); sb.append(name); sb.append(","); for (Purchase inner : purchaseList) { sb.append(inner); } return sb.toString(); }
java Syntax (Toggle Plain Text)
public String toString() { StringBuffer sb = new StringBuffer(); sb.append("Owner:"); //TODO return sb.toString(); }
java Syntax (Toggle Plain Text)
import java.util.ArrayList; import java.util.Date; import java.util.List; public class Superstar { Owner owner; public Superstar() { owner = new Owner(); String supplierName = "Smith"; Date date = new Date(); String animalName = "dog"; int price = 100; owner.add(supplierName, date, animalName, price); date = new Date(); long time = date.getTime() - 8888888888L; date.setTime(time); owner.add(supplierName, date, "cow", 1000); owner.add("Byron", date, "cat", 5); System.out.println(owner); //first simple question int numberOfSales = owner.getNumberOfSales(); System.out.println("numberOfSales=" + numberOfSales); } public static void main(String[] args) { new Superstar(); } }
Java Syntax (Toggle Plain Text)
public class Owner { private List<Supplier> supplierList = new ArrayList<Supplier>(); // by name public Supplier getSupplier(String supplierName) { for (Supplier inner : supplierList) { if (inner.getName().equals(supplierName)) { return inner; } } return (Supplier) null; } public void add(String supplierName, Date currDate, String animalName, int animalPrice) { Animal animal = new Animal(animalName, animalPrice); Purchase purchase = new Purchase(currDate, animal); // check for supplier Supplier supplier = getSupplier(supplierName); if (supplier == null) { supplier = new Supplier(supplierName, purchase); // add new suplier to supplierList supplierList.add(supplier); } else { //supplier exist,add supplier.add(purchase); } } @Override public String toString() { StringBuffer sb = new StringBuffer(); sb.append("Owner:"); for (Supplier inner : supplierList) { sb.append("\n"); sb.append(inner); } return sb.toString(); } public int getNumberOfSales() { int numberOfSales = 0; for (Supplier inner : supplierList) { numberOfSales += inner.getNumberOfSales(); } return numberOfSales; } }
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
![]() |
Other Threads in the Java Forum
- Previous Thread: Network Monitoring
- Next Thread: Help with java swing!
| Thread Tools | Search this Thread |
2dgraphics android api apple applet application arguments array arrays automation banking binary binarytree bluetooth capture chat chatprogramusingobjects class classes client code color component count database derby design eclipse eclipsedevelopment encryption error exception fractal game givemetehcodez graphics gridlayout gui html ide if_statement image input integer interface j2me java javadesktopapplications javaprojects jlabel jni jpanel julia keyword linux list loop macintosh map method methods midlethttpconnection mobile netbeans newbie nullpointerexception object os print printing problem producer program programming project projectideas read recursion reference replaysolutions ria scanner screen server set size sms sort sourcelabs sql stop string swing threads transforms tree ui unicode validation windows






