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

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.

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?

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())

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

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:

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();
        }

For Purchase:

public String toString() {
            StringBuffer sb = new StringBuffer();
            sb.append("Purchase:");
            sb.append("Date=");
            sb.append(date);
            sb.append(",");
            sb.append(animal);
            return sb.toString();
        }

For Supplier:

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();
        }

For Owner:

public String toString() {
            StringBuffer sb = new StringBuffer();
            sb.append("Owner:");
            //TODO
            return sb.toString();
        }

DATABASE FILLING

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();
    }
}
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;
        }
    }

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

...

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

This article has been dead for over six months. Start a new discussion instead.