I was wondering why this isn't working. I looked at another post that suggested the method I used for calling methods from Objects stored in an array but it doesn't seem to be working. I should clarify. I am referring to the printPurchases and totalCost methods. More specifically how they don't seem to be allowing me to call from the Purchase object at index i, but instead appear to be calling from the get(i) part. It is highlighted in red in my eclipse application.
public class Customer {
private String name, address;
double total;
private ArrayList purchases = new ArrayList();
public Customer(String name, String address){
this.address=address;
this.name=name;
}
public void makePurchase(Purchase purchase){
purchases.add(purchase);
}
public String printPurchases(){
for(int i=0; i<purchases.size(); i++){
return **name+"\t"+address+purchases.get(i).toString();**
}
return"";
}
public double totalCost(){
total=0;
for(int i=0; i<purchases.size(); i++){
total = **total+purchases.get(i).getCost();**
}
}
}
public double totalCost(){...}