Problem Description: Passengers are to be added/deleted to/from the queue. Each
ID: 3737122 • Letter: P
Question
Problem Description: Passengers are to be added/deleted to/from the queue. Each passenger has his Name, Ticket type and Seat number. 1) Write the code for the following methods to implement a queue: - Adding passengers to a queue. (2 marks) - Removing passengers from queue. (3 marks) - Scanning a passenger's data. Details of a passenger (from the queue) are to be displayed. (3 marks) -Quit and display the remaining queue size and values. (2 marks) 2) Run the program by adding at least three sets of values for passengers in the Queue. 3) Delete 1 value from the queue (remember queue follows FIFO), and print the removed passenger. Below is the file in which students will have to write their code wherever they find a comment:/ YOUR CODE HERE PassengerData.java import java.util.Scanner; class PassengerData extends Passenger f public static CreateQueuexPassengen createQueue public PassengerData) super): public void menuOptionsOf char choice;Explanation / Answer
package chegg;
import java.util.Iterator;
import java.util.Scanner;
import chegg.Passanger;
import chegg.CreateQueue;
public class PassangerData extends Passanger
{
public static CreateQueue <Passanger> createQueue;
public PassangerData()
{
super();
}
public void menuOptions()
{
char choice;
do
{
System.out.println("Ënter Add, Remove,Scan,or quit");
Scanner input=new Scanner(System.in);
choice=input.nextLine().toUpperCase().charAt(0);
switch(choice)
{
case 'A':Passanger item =new Passanger();
System.out.println("Enter Passanger Name");
String name=input.nextLine();
item.setName(name);
System.out.println("Enter Passanger Seat_no");
int seat_no=input.nextInt();
item.setSeat_no(seat_no);
System.out.println("Enter Passanger Ticket_Type");
String ticket_type=input.next();
item.setTicket_type(ticket_type);
createQueue.enqueue(item);
break;
case 'R':Passanger itemRemoved =new Passanger();
itemRemoved=createQueue.dequeue();
System.out.println("Passanger "+itemRemoved.getName()+" "+itemRemoved.getTicket_type()+" "+itemRemoved.getSeat_no()+" Removed");
break;
case 'S':System.out.println("Enter the Passanger whose details are needed");
String namePassanger=input.nextLine();
Iterator<Passanger> itr =createQueue.iterator();
boolean check=false;
while( itr.hasNext())
{
Passanger pas =itr.next();
if (pas.getName().equals(namePassanger))
{
check=true;
System.out.println("Passanger Name"+pas.getName());
System.out.println("Seat No"+pas.getSeat_no());
System.out.println("Ticket Type"+pas.getTicket_type());
break;
}
}
if(!check)
System.out.println("Passanger with name "+namePassanger+" not found");
break;
case 'Q':System.out.println("Leaving queue with"+ createQueue.size() +"Passangers ");
Iterator<Passanger> itrlist =createQueue.iterator();
while( itrlist.hasNext())
{
Passanger pas =itrlist.next();
System.out.println("Passanger Name "+pas.getName());
System.out.println("Seat No "+pas.getSeat_no());
System.out.println("Ticket Type "+pas.getTicket_type());
}
break;
default:System.out.println("Wrong input");
}
}while(choice!='q');
}
public static void main(String args[])
{
createQueue=new CreateQueue<Passanger>();
PassangerData data=new PassangerData();
data.menuOptions();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.