Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- public class AppTicket {
- public static void main(String[] args) {
- ArrayList<Ticket> tickets = new ArrayList<Ticket>();
- tickets.add(new Ticket("Avengers", 8.00));
- tickets.add(new Ticket("Mozart", 8.00));
- tickets.add(new DiscountTicket("Mozart", 8.00, "John Smith"));
- tickets.add(CheckPeople(new GroupTicket("Mozart", 8.00, 2)));
- getInfo(tickets);
- }
- public static Ticket CheckPeople(GroupTicket gt) {
- if (gt.getPeople() >= 20) {
- gt.setPrice(gt.getPeople() * (gt.getPrice() - 2));
- }
- return gt;
- }
- public static void getInfo(ArrayList<Ticket> tickets) {
- int people = 0;
- double sum = 0;
- for (int i = 0; i < tickets.size(); i++) {
- people = people + tickets.get(i).getPeople();
- sum += tickets.get(i).getPrice();
- }
- System.out.println("Number of people from these tickets: " + people);
- System.out.println("The total sum of these tickets: " + sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement