Wednesday, 18 September 2013

Loop through arrayList to get values of an abstract method

Loop through arrayList to get values of an abstract method

Ok I have an abstract class 'Order':
public abstract class Order {
protected String location;
protected double price;
public Order(double price, String location){
this.price = price;
this.location = location;
}
public abstract double calculateBill();
public String getLocation() {
return location;
}
public double getPrice() {
return price;
}
public abstract String printOrder(String format);
}
I also have 3 classes that implement it that are similar except, of
course, that they calculateBill differently according to tax, tariff, etc.
now I am trying to create and OrderManager class to manage them. This is
what I have so far
public class OrderManager {
private ArrayList<Order> orders;
public OrderManager() {
}
public OrderManager(ArrayList<Order> orders) {
this.orders = orders;
}
public void addOrder(Order o) {
orders.add(o);
}
public ArrayList<Order> getOrdersAbove(double val) {
for (Order o : orders) {
}
}
I'm having trouble with the getOrdersAbove method which should return and
array list of orders whose bill is above val. Being the calculateBill is
abstract and implemented in each subclass of order I should just be able
to call it correct? Also if that is the case then shouldn't OrderManager
extend Order? Or just being in the same package would allow me to call
it's methods? Or am I going about it all wrong?
Thanks for any and all help!

No comments:

Post a Comment