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
The recheck document button, which resets the spelling and grammar checker to flag previously ignored errors, is located in the
kumpel [21]
The answer is b and c
7 0
3 years ago
Given two lists: L1=[10,12,14] and L2=[20,22,24] 2
OleMash [197]

Answer:

Explanation:

(i) L1+L2  Error:

L1=[10,12,14]  

L2=[20,22,24]       # {n. 2 delete}

L1+L2  

ans =

   30    34    38

(ii) L1*2

ans =

 20    24    28

(iii) L1

L1 =

  10    12    14

8 0
3 years ago
Your supervisor has asked you to help with the orientation of three new office employees. Topics you're asked to present include
Crazy boy [7]

Answer:

Policy manual

Explanation:

A written document that is designed by the company to decide the rules and regulations for the employee to guide them about attendance and evaluation to achieve the desired goals is called Policy manual.

A handbook is provided to the employee at the time of joining of Job. All the policies related to employee such as dress code, attendance policy and evaluation policy. All the rules and regulations related to office are also present in this document.

The purpose of this document is to inform the new employees about guidelines of the company.

7 0
4 years ago
If Scheme were a pure functional language, could it include DISPLAY ? Why or why not?​
VARVARA [1.3K]

Answer:

When Scheme is a pure functional language, it cannot include the function DISPLAY. Since the pure functional languages will return the same value whenever the same expression is evaluated, and the DISPLAY would be the output and thus it cannot be part of the purely functional language. Thus in the pure functional language we can evaluate the expressions with the same arguments and it returns the same value since there is no state to change.

Explanation:

4 0
3 years ago
Which hardware device connects your network to the internet?
pentagon [3]
The Ethernet Cord 

Hope this helps,

kwrob :)

6 0
4 years ago
Other questions:
  • A 5-inch, f/10 telescope has a 2-inch eyepiece focal. Its magnifying power is: (PLEASE HELP)
    6·1 answer
  • When you compose a message, you want your audience to find the information it needs quickly and to understand what it finds. You
    11·1 answer
  • A general rule for adding text to a slide is ____.
    7·2 answers
  • i got a set of headphones and when i plug them into my speakers the right side only works how do i fix the left side of them
    12·1 answer
  • A computer has the following parameters Operation Frequency Cycles Arithmetic/Logical instructions 65% 1 Register load operation
    11·1 answer
  • _________ local variables retain their value between function calls.
    9·1 answer
  • Is Missouri a free state or a slave state​
    13·2 answers
  • What happens if a computer lags too much?
    14·2 answers
  • Does anyone know what this logo is??
    11·2 answers
  • You find a picture of a famous department store online that would be great to include in a project of yours. What should you do
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!