Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 7.4.6: Airline Tickets The ticketing system at the airport is broken, and passengers have lined up to board the plane in the incorrect order.

Exercise 7.4.6: Airline Tickets

The ticketing system at the airport is broken, and passengers have lined up to board the plane in the incorrect order. The line of passengers has already been created for you, and is stored in the ArrayList tickets in the AirlineTester class.

Devise a way to separate passengers into the correct boarding groups.

Currently, there is an AirlineTicket class that holds the information for each passengers ticket. They have a name, seat, row, and boarding group.

Use the TicketOrganizer class to help fix the order of passengers boarding. First, create a constructor that takes an ArrayList of AirlineTickets and assigns it to the instance variable tickets. Then, create a getTickets method to get the ArrayList of AirlineTickets.

In the TicketOrganizer class, create a method called printPassengersByBoardingGroup that prints out the name of the passengers organized by boarding group. The boarding groups go from 1-5, and have been predetermined for you. This should print the boarding group followed by all passengers in the group:

Boarding Group 1: Passenger 2 Passenger 9 Passenger 11 Passenger 12 Boarding Group 2: Passenger 4 Boarding Group 3: Passenger 5 Passenger 6 Passenger 7 Passenger 8 Passenger 13 Boarding Group 4: Passenger 14 Boarding Group 5: Passenger 1 Passenger 3 Passenger 10 Passenger 15

You should also create a method named canBoardTogether which determines if passengers already in line in the tickets ArrayList can board with the people they are standing next to in line. If a passenger has the same row and boarding group as the person behind them, this method should print that those two passengers can board together. For instance if Passenger 11 and Passenger 12 are both in Row 3, and in Boarding Group 4, the method would print:

Passenger 11 can board with Passenger 12.

If there are no passengers that can board together, then it should print that out to the console.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Status: Not Submit Submit + Continue Exercise 7.4.6: Airline Tickets 5 points Let's Go! Show Exercis The ticketing system at the airport is broken, and passengers have lined up to board the plane in the incorrect order. The line of passengers has already been created for you, and is stored in the ArrayList tickets in the AirlineTester class. Devise a way to separate passengers into the correct boarding groups. Currently, there is an AirlineTicket class that holds the information for each passengers ticket. They have a name, seat, row, and boarding group. Use the Ticketorganizer class to help fix the order of passengers boarding. First, create a constructor that takes an ArrayList of Airline Tickets and assigns it to the instance variable tickets. Then, create a getTickets method to get the ArrayList of AirlineTickets. In the Ticketorganizer class, create a method called printPassenger sByBoardingGroup that prints out the name of the passengers organized by boarding group. The boarding groups go from 1-5, and have been predetermined for you. This should print the boarding group followed by all passengers in the group: Boarding Group 1: Passenger 2 Passenger 9 Passenger 11 Passenger 12 Boarding Group 2: Passenger 4 Boarding Group 3: Passenger 5 Passenger 6 Passenger 7 Passenger 8 Passenger 13 Boarding Group 4: Passenger 14 Boarding Group 5: Passenger 1 Passenger 3 Passenger 10 ArrayList Status: Not Submit Submit + Continue Exercise 7.4.6: Airline Tickets 6 points Let's Go! Show Exercis Boarding Group 1: Passenger 2 Passenger 9 Passenger 11 Passenger 12 Boarding Group 2: Passenger 4 Boarding Group 3: Passenger 5 Passenger 6 Passenger 7 Passenger 8 Passenger 13 Boarding Group 4: Passenger 14 Boarding Group 5: Passenger 1 Passenger 3 Passenger 10 Passenger 15 You should also create a method named canBoardTogether which determines if passengers already in line in the tickets ArrayList can board with the people they are standing next to in line. If a passenger has the same row and boarding group as the person behind them, this method should print that those two passengers can board together. For instance if Passenger 11 and Passenger 12 are both in Row 3, and in Boarding Group 4, the method would print: Passenger 11 can board with Passenger 12. If there are no passengers that can board together, then it should print that out to the console. ArrayList 7.4.6: Airline Tickets Save Submit + Continue BO = 10 1 import java.util.ArrayList; 2 3 public class Airline Ticket Tester 4- { 5 public static void main(String[] args) 6 ArrayList tickets = new ArrayList(); 8 //This creates a randomized list of passengers 9 addPassengers(tickets); for(Airline Ticket elem: tickets) 11 - { 12 System.out.println(elem); 13 14 //This creates a TicketOrganizer object 15 TicketOrganizer ticketOrganizer = new TicketOrganizer (tickets); 16 17 1/These are the methods of the ticketOrganizer in action 18 System.out.println(" Passengers Ordered by Boarding Group:"); 19 ticketOrganizer.printPassengersByBoardingGroup(); 20 System.out.println(" Passengers in line who can board together:"); 21 ticketOrganizer.canBoardTogether(); 22 23 24 I/Do not touch this method! It is adding random passengers to the AirlineTicket array public static void addPassengers(ArrayList tickets) 26 - { 27 String[] seats = {"A", "B", "C", "D", "E", "F"}; 28 for(int index = 0; index 7.4.6: Airline Tickets Save Submit + Continue 1 public class TicketOrganizer 2 - { 3 private ArrayList tickets; 4 5 6 } 7 > 7.4.6: Airline Tickets Save Submit + Continue my 0 ili 1 public class AirlineTicket 2- { 3 private String[] seats = ["A", "B", "C", "D", "E", "F"}; 4 private String name; 5 private String seat; 6 private int boardingGroup; 7 private int row; 8 9 public AirlineTicket(String name, String seat, int boardingGroup, int row) 10 - { 11 this.name = name; 12 if(isValidSeat(seat)) 13- { 14 this. seat = seat; 15 } 16 this.boardingGroup = boardingGroup; 17 this.row = row; 18 19 } 20 21 private boolean isValidSeat(String seat) 22- { 23 boolean isValidSeat = false; 24 for(String elem: seats) 25- { 26 if(seat.equals(elem)) 27- { 28 isValidSeat = true; 29 } 30 } 31 return isValidSeat; 32 } 33 34 public String getSeat) 35 { 36 return this seat. > 7.4.6: Airline Tickets Save Submit + Continue 0 2 0 for (String elem: seats) { if(seat.equals(elem)) { isValidSeat = true; } } return isValidSeat; } public String getSeat() { return this. seat; } 24 25- 26 27 28 29 30 31 32 33 34 35 - 36 37 38 39 40 41 42 43 44 45- 46 47 48 49 50 - 51 52 53 54 55 - 56 57 58 59 public String getName() { return this.name; } public int getBoardingGroup { return this. boardingGroup; } public int getRow() { return this.row; } public String toString() { return name + " Seat: " +seat + " Row: " + row + " Boarding Group: " + boardingGroup; } > }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago