Advertisement
KechevD

Lesson 23 Inheritage_AppTicket

May 18th, 2020
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class AppTicket {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. ArrayList<Ticket> tickets = new ArrayList<Ticket>();
  8. tickets.add(new Ticket("Avengers", 8.00));
  9. tickets.add(new Ticket("Mozart", 8.00));
  10. tickets.add(new DiscountTicket("Mozart", 8.00, "John Smith"));
  11. tickets.add(CheckPeople(new GroupTicket("Mozart", 8.00, 2)));
  12.  
  13. getInfo(tickets);
  14. }
  15.  
  16. public static Ticket CheckPeople(GroupTicket gt) {
  17. if (gt.getPeople() >= 20) {
  18. gt.setPrice(gt.getPeople() * (gt.getPrice() - 2));
  19. }
  20. return gt;
  21. }
  22.  
  23. public static void getInfo(ArrayList<Ticket> tickets) {
  24. int people = 0;
  25. double sum = 0;
  26.  
  27. for (int i = 0; i < tickets.size(); i++) {
  28. people = people + tickets.get(i).getPeople();
  29. sum += tickets.get(i).getPrice();
  30. }
  31.  
  32. System.out.println("Number of people from these tickets: " + people);
  33. System.out.println("The total sum of these tickets: " + sum);
  34. }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement