Guest User

Untitled

a guest
Nov 16th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. public class ProductList extends ArrayList<Product>
  2. {
  3. public void addProduct(Product p)
  4. {
  5. this.add(p);
  6. }
  7. public void removeProduct(int index)
  8. {
  9. this.remove(index);
  10. }
  11. public double getTotalPrice()
  12. {
  13. double sum = 0;
  14. for(Product p : this){ sum += p.getPrice(); }
  15. return sum;
  16. }
  17. public void printList()
  18. {
  19. for(Product p : this){System.out.println("Name: " + p.getName() + " Price: " + p.getPrice() + " euro.");}
  20. }
  21. public void printListWithIndex()
  22. {
  23. for(int i=0; i<this.size() ; i++)
  24. {
  25. System.out.println(i + ". Name: " + this.get(i).getName() + " Price: " + this.get(i).getPrice() + " euro.");
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment