1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
expeople1 [14]
3 years ago
6

You should also create a method named canBoardTogether which determines if passengers already in line in the tickets ArrayList c

an 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:
Computers and Technology
1 answer:
qaws [65]3 years ago
3 0

Answer:

See explaination

Explanation:

import java.util.ArrayList;

public class Main

{

public static void main(String[] args)

{

ArrayList<AirlineTicket> tickets = new ArrayList<AirlineTicket>();

//This creates a randomized list of passengers

addPassengers(tickets);

for(AirlineTicket elem: tickets)

{

System.out.println(elem);

}

//This creates a TicketOrganizer object

TicketOrganizer ticketOrganizer = new TicketOrganizer(tickets);

//These are the methods of the ticketOrganizer in action

System.out.println("\nPassengers Ordered by Boarding Group:");

ticketOrganizer.printPassengersByBoardingGroup();

System.out.println("\nPassengers in line who can board together:");

ticketOrganizer.canBoardTogether();

}

//Do not touch this method! It is adding random passengers to the AirlineTicket array

public static void addPassengers(ArrayList<AirlineTicket> tickets)

{

String[] seats = {"A","B","C","D","E","F"};

for(int index = 0; index< 15; index++)

{

int random = (int)(Math.random() * 5);

AirlineTicket ticket = new AirlineTicket("Passenger " + (index+1), seats[random], ((int)(Math.random()*5)+1), ((int)(Math.random()*8)+1));

tickets.add(ticket);

}

}

}

class TicketOrganizer

{

private ArrayList<AirlineTicket> tickets ;

//constructor with parameter as an arraylist of AirlineTicket

public TicketOrganizer(ArrayList<AirlineTicket> tickets)

{

this.tickets = tickets;

}

//methhods to return the arraylist of airlines

public ArrayList<AirlineTicket> getTickets()

{ //re-organize the ticket first

ArrayList<AirlineTicket> tickets_organized = new ArrayList<AirlineTicket>();

for(int i=1; i<=5; i++)

{

for(AirlineTicket ticket: tickets)

{

if(ticket.getBoardingGroup() == i)

{

tickets_organized.add(ticket);

}

}

}

return tickets_organized;

}

//print the tickets based on boardingGroup

public void printPassengersByBoardingGroup()

{

int count = 0;

for(int i=1; i<=5; i++)

{

System.out.println("Boarding Group " + i + ":");

for(AirlineTicket ticket : tickets)

{

if(ticket.getBoardingGroup() == i)

{

System.out.println("Passenger " + ticket.getName());

}

}

}

}

//check if two persons can sit together

public void canBoardTogether()

{

for(int i=0; i<15; i++)

{

String str = "Passenger "+ (i + 1) +" can board with Passengers";

for(int j=i+1; j<14; j++)

{

boolean isRowEqual = tickets.get(i).getRow() == tickets.get(j).getRow();

boolean isBoardGroupEqual = tickets.get(i).getBoardingGroup() == tickets.get(j).getBoardingGroup();

//if one of them false, print the all added Passengers

if(!(isRowEqual && isBoardGroupEqual))

{

if(j != i+1)

{

System.out.println(str);

}

break;

}

str += " " + (j+1);

}

}

}

}

class AirlineTicket

{

private String[] seats = {"A","B","C","D","E","F"};

private String name;

private String seat;

private int boardingGroup;

private int row;

public AirlineTicket(String name, String seat, int boardingGroup, int row)

{

this.name = name;

if(isValidSeat(seat))

{

this.seat = seat;

}

this.boardingGroup = boardingGroup;

this.row = row;

}

private boolean isValidSeat(String seat)

{

boolean isValidSeat = false;

for(String elem: seats)

{

if(seat.equals(elem))

{

isValidSeat = true;

}

}

return isValidSeat;

}

public String getSeat()

{

return this.seat;

}

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;

}

}

You might be interested in
Roark has just joined a company and in his role as a lead analyst, he will be responsible for determining which systems developm
hram777 [196]

Answer:

Agile/adaptive methods.

Explanation:

The user has just decided to join a firm and will also be accountable to determine whether that system development technique that group uses to establish the latest software for a significant medical distributor to his position as just a lead analyst.

After that, he consumes a week for the purpose to understand his group members for reason to know their strengths and weakness and how would they work under pressure.

So, the following method is required for him to understand about the disadvantages of each of them.

4 0
3 years ago
Problem # 1 [End of chapter problem] The following character encoding is used in a data link protocol: A: 01100111 B: 11110011 F
Whitepunk [10]

Answer:

a) 00000100 01000111 11100011 11100000 01111110  

b) 01111110 01000111 11100011 11100000 11100000 11100000 01111110 01111110

c) 01111110 01000111 110100011 11100000 011111010 0111110  

Explanation:

5 0
3 years ago
How to look at things you previously applied to on handshake
Radda [10]

Answer:

If you mean what I think you mean, You would want to memorize the handshake. or make signs for it or words. kinda like a dance routine.

Explanation:

3 0
3 years ago
John is writing a code instructing the character to move forward 10 steps, choose a number between 1 to 10, and if the number is
gladu [14]

Answer: bro im suck on the same thing

Explanation:

8 0
3 years ago
Is phone data used when connected to wifi
finlep [7]
I do not think so, no.
7 0
3 years ago
Other questions:
  • Witch printer covers a large range of colors than any other printer does
    15·2 answers
  • "a​ _______ network delivers user data in many different geographical locations and makes those data available in a way that min
    5·1 answer
  • 10. Question
    15·1 answer
  • Write a program that creates a dictionary containing the U.S. states as keys and their capitals as values. (Use the Internet to
    10·1 answer
  • Is there any level after genius?
    8·1 answer
  • Shipments of compact digital cameras dropped by 42% due to the industry being unable to adjust to changes in the ________. a. ec
    11·1 answer
  • Which statement describe the advantages of using XML? more than one answer can be correct
    9·1 answer
  • Inputting a range of numbers comprising a batch and then inputting each serially numbered document is characteristic of the cont
    11·1 answer
  • In the software development process, which review studies the software design before it is released for coding?
    7·1 answer
  • Which statement best describes network security?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!