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
Hayne is starting his own business as a psychotherapist and needs to post a website advertising his services,contact information
irina1246 [14]

The kind of website which would best suit Hayne's needs is a: C) Dynamic website.

A website is the collective name that is used to describe series of interconnected webpages having a unique domain name.

Basically, a website is an HTML document which comprises codes, tags, images, audios, and videos that are integrated to make them responsive and interactive with clients (end users).

In Computer and Technology, there are four (4) main types of website and these include:

  • Static website.
  • E-commerce website.
  • Scripted website.
  • Dynamic website.

A dynamic website is a type of website which is designed to contain information that automatically changes based on the client, time zone, time of the day, language, services, and other factors.

In this scenario, the kind of website which would best suit Hayne's needs is a dynamic website because his services, tips or contact information may change.

Read more: brainly.com/question/21694571

7 0
3 years ago
How does a Cloud-first strategy approach a client's migration to the Cloud?by removing outside ecosystem partners from the Cloud
belka [17]

Cloud-first strategies are <em>operating methods</em> wherein teams move all or most of their infrastructure to <em>cloud computing systems</em><em>  </em>such as Web Services, and the further discussion can be defined as follows:

  • It stores assets, including quest and <em>secure resources</em>, in the cloud rather than employing <em>physical resources</em> including such server clusters.
  • This approaches a client's migration to the <em>Cloud by integrating multiple services </em>together to serve the client's business needs.

Therefore, the final answer is "Last choice".

Learn more:

brainly.com/question/1256812

3 0
3 years ago
What is bug in computer?​
Anton [14]

Answer:

<h2>A bug in a computer is refered to as a "computer virus" its where certain things on the computer or apps on it aren't working like they were designed to. </h2>

Explanation:

<h2>Hope this helps:)!</h2>
6 0
3 years ago
I need help pls, in this code if add row for example :
tankabanditka [31]
I thing is going project experiment everyone make plans and
3 0
4 years ago
What are the high and low temperatures on Saturn? (C)
slava [35]
Saturn contains three layers of clouds. The upper layers of ammonia ice have temperatures ranging from minus 280 F to minus 170 F. The next layer contains water ice, with temperatures from minus 127 F to 26.Temperatures in the lower layers climb as high as 134 F.
8 0
3 years ago
Other questions:
  • Which of the following is NOT a group on the Slide Master tab?
    6·1 answer
  • Which Internet appliance can take action to potentially stop a network attack from taking place?
    6·1 answer
  • If a user wants to change one small section of the formatting of a document and leave the rest the same, which process should be
    14·1 answer
  • 10010010 + 01100010 =
    11·1 answer
  • Which of the following illustrates an example of a string data type?
    15·2 answers
  • What is considered to be the core of the Unix operating system ?
    14·1 answer
  • Naynar kis dhrm se sambandhit hai​
    15·2 answers
  • 4. Describe a report that a company might want to create and run on a regular basis. (1-3
    10·1 answer
  • Place a check next to each of the choices that describe an example of proper ergonomics. (more than 1 answer)
    7·2 answers
  • A workstation is out of compliance with the group policy standards set by the domain what command prompt would you use to ensure
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!