Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ProductList extends ArrayList<Product>
- {
- public void addProduct(Product p)
- {
- this.add(p);
- }
- public void removeProduct(int index)
- {
- this.remove(index);
- }
- public double getTotalPrice()
- {
- double sum = 0;
- for(Product p : this){ sum += p.getPrice(); }
- return sum;
- }
- public void printList()
- {
- for(Product p : this){System.out.println("Name: " + p.getName() + " Price: " + p.getPrice() + " euro.");}
- }
- public void printListWithIndex()
- {
- for(int i=0; i<this.size() ; i++)
- {
- System.out.println(i + ". Name: " + this.get(i).getName() + " Price: " + this.get(i).getPrice() + " euro.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment