4.14 LAB: Ticketing service (Queue)
Given main(), complete the program to add people to a queue. The program should read in a list of people's names including "You" (ending with -1), adding each person to thepeopleInQueue queue. Then, remove each person from the queue until "You" is at the head of the queue. Include print statements as shown in the example below.
Ex. If the input is
Zadie Smith Tom Sawyer You Louisa Alcott
the output is
Welcome to the ticketing service... You are number 3 in the queue. Zadie Smith has purchased a ticket. You are now number 2 Tom Sawyer has purchased a ticket. You are now number 1 You can now purchase your ticket!
Code that I have been provided:
import java.util.Scanner;
import java.util.LinkedList;
import java.util.Queue;
public class TicketingService {
public static void main (String[] args) {
Scanner scnr = new Scanner(System.in);
String personName = "";
int counter = 0;
int youPosition;
Queue
personName = scnr.nextLine();
while (!personName.equals("-1")) {
// TODO: Add personName to peopleInQueue and
// determine position of "You" (youPosition)
personName = scnr.nextLine();
}
System.out.println("Welcome to the ticketing service...
");
System.out.println("You are number " + youPosition + " in the
queue.");
// TODO: In a loop, remove head person from peopleInQueue,
// output their name and that they have purchased a ticket,
// then output your position in the queue. When you are at
// the head, output that you can purchase your ticket.
}
}
import java.util.Scanner;
import java.util.LinkedList;
import java.util.Queue;
public class TicketingService {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
String personName = "";
int counter = 0;
int youPosition = 0;
Queue peopleInQueue = new LinkedList();
personName = scnr.nextLine();
while (!personName.equals("-1")) {
peopleInQueue.add(personName);
++counter;
if (personName.equals("You")) {
youPosition = counter;
}
personName = scnr.nextLine();
}
System.out.println("Welcome to the ticketing service... ");
System.out.println("You are number " + youPosition + " in the queue.");
// TODO: In a loop, remove head person from peopleInQueue,
// output their name and that they have purchased a ticket,
// then output your position in the queue. When you are at
// the head, output that you can purchase your ticket.
for (int i = youPosition - 1; i >= 1; i--) {
System.out.println(peopleInQueue.remove() + " has purchased a ticket.");
System.out.println("You are now number " + i);
}
System.out.println("You can now purchase your ticket!");
}
}

LAB: Ticketing service (Queue)Given main(), complete the program to add people to a queue. The program should read in a list of people's names including "You" (ending with -1), adding each person to the peopleInQueue queue. Then, remove each person from the queue until "You" is at the head of the queue. Include print statements as shown in the example below.Ex. If the input is:Zadie Smith Tom Sawyer You Louisa Alcott -1the output is:Welcome to the ticketing service... You are number 3 in the queue. Zadie Smith has purchased a ticket. You are now number 2 Tom Sawyer has purchased a ticket. You are now number 1 You can now purchase your ticket!TicketingService.javaimport java.util.Scanner; import java.util.LinkedList; import java.util.Queue; public class TicketingService { public static void main (String[] args) { Scanner scnr = new Scanner(System.in);...
14.11 LAB: Ticketing service (queue) Given main(). complete the program to add people to a queue. The program should read in a list of people's names including "You" (ending with-1), adding each person to the peopleInQueue queue. Then, remove each person from the queue until "You" is at the head of the queue. Include print statements as shown in the example below. Ex. If the input is: Zadie Smith Tom Sawyer You Louisa Alcott -1 the output is: Welcome to the ticketing service... You are number 3 in the queue. Zadie...
THE ENTIRE CODE SHOULD BE IN JAVA Playlist (output linked list) Given main(), complete the SongNode class to include the printSongInfo() method. Then write the Playlist class' printPlaylist() method to print all songs in the playlist. DO NOT print the dummy head node. Ex: If the input is: Stomp! 380 The Brothers Johnson The Dude 337 Quincy Jones You Don't Own Me 151 Lesley Gore -1 the output is: LIST OF SONGS ------------- Title: Stomp! Length: 380 Artist: The Brothers...
JAVA PROGRAMMING Given main(), complete the SongNode class to include the printSongInfo() method. Then write the Playlist class' printPlaylist() method to print all songs in the playlist. DO NOT print the dummy head node. Ex: If the input is: Stomp! 380 The Brothers Johnson The Dude 337 Quincy Jones You Don't Own Me 151 Lesley Gore -1 the output is: LIST OF SONGS ------------- Title: Stomp! Length: 380 Artist: The Brothers Johnson Title: The Dude Length: 337 Artist: Quincy Jones...
Java:Netbeans-Use the LinkedList class to simulate a queue, and use the add method to simulate the enqueue, and the remove method to simulate the dequeue method for a Queue. Remember to use FIFO. Need help with 0. Add New Microchips pushMicroChip(), popMicroChip() and . To simulate this, you will create a menu option 0, which will generate 100 microchip long objects, and place them into a stack of microchips. Those microchip objects will be generated by using the System.nanotime() method. ...
This lab will give you a practice with both queue and stack ADTs. In this work, you are to determine if an input string is a palindrome. A string of characters is a palindrome if and only if it reads the same forward and backward. Examples: eye, abba, civic, radar, and so on. Sample Output: Please enter a string of characters: abba The given string is a palindrome. Want to examine another string? (y/n): y Please enter a string of...
You will write a single java program called MadLibs. java. This file will hold and allow access to the values needed to handle the details for a "MadLibs" game. This class will not contain a maino method. It will not ask the user for any input, nor will it display (via System.out.print/In()) information to the user. The job of this class is to manage information, not to interact with the user.I am providing a MadLibsDriver.java e^{*} program that you can...
Modify the following given Java program. You are expected to modify the supplied Exercise1.java to print just the last lines of each paragraph in HTML format. Copy and paste the Sample input on the console then print the Expected output. import java.util.Scanner; public class Exercise1 { /** A simple static string for HTML & table header. */ private static final String HTMLHeader = "<!DOCTYPE html>\n" + " <html>\n" + " <head>\n" + " <title>CSE: Exercise 1</title>\n" + " </head>\n" +...
Rewrite the following program using the DecimalFormat class so that your output looks like that below. Once again, the example is not calculated as 3/10ths of a percent. Welcome to NIU Investments! Please enter the amount you would like to invest today: 34543.25 Total Investment: $34,543.25 Service Charge: $22.33 ------------- Total Amount Due: $34,565.58 Thank you for your investment! Program: package org.students; import java.util.Scanner; public class NIUInvestments { //Declaring constant public static final double SCHARGE=0.0006464; public...
convert this program from java to c++ import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String name,seat,fcls; int st,i; String price; int ch1; char ch; seat=""; String time[]={"7.00","9.00","11.00","13.00","15.00"}; String arrive[]={"9.30","11.30","13.30","15.30","17.30"}; int cp[]=new int[5]; do{ System.out.println("Welcome to CSO1511 Flight Booking System"); System.out.println("Enter full name?"); name=sc.nextLine(); System.out.println("The available travel times for flights are:"); System.out.println(" Depart \t Arrive"); System.out.println("1. 7.00 \t\t 9.30"); System.out.println("2. 9.00 \t\t 11.30"); System.out.println("3. 11.00 \t\t 13.30"); System.out.println("4. 13.00 \t\t 15.30"); System.out.println("5. 15.00 \t\t...