Note that there are some explanatory texts on larger screens.

plurals
  1. POreturn object of a certain 'type' from array list
    primarykey
    data
    text
    <p>I have an order class:</p> <pre><code>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); } </code></pre> <p>It is extended by three subclasses 'NonProfitOrder', 'RegularOrder', and 'OverseasOrder' each of which only differ in the way they calculateBill().</p> <p>Then I have and OrderManger class</p> <pre><code>public class OrderManager { private ArrayList&lt;Order&gt; orders; public OrderManager() { } public OrderManager(ArrayList&lt;Order&gt; orders) { this.orders = orders; } public void addOrder(Order o) { orders.add(o); } public ArrayList&lt;Order&gt; getOrdersAbove(double val) { for (Order o : orders) { double bill = o.calculateBill(); if (bill &gt; val) orders.add(o); } return orders; } public int numOrders() { return orders.size(); } public String printOrders() { for (Order o : orders){ String format = "Long"; } return printOrders("Long"); } public String printOrders(String type) { for (Order o : orders) { } } public double totalBill() { double sum = 0; for(Order o : orders) { sum = o.calculateBill(); } return sum; } } </code></pre> <p>I believe that i have everything working correctly, except that I am having trouble with the printOrders(String type) which return a string of all orders of 'type' where 'type' is "Regular", "Overseas", or "NonProfit". My question would be what is the correct way to loop through and array list and only returning the objects of a given 'type'?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload