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 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.java
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 peopleInQueue = new LinkedList(); 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; QueuepeopleInQueue = new LinkedList (); personName = scnr.nextLine(); while (!personName.equals("-1")) { peopleInQueue.add(personName); if (personName.equals("You")) { youPosition = counter + 1; } counter++; personName = scnr.nextLine(); } System.out.println("Welcome to the ticketing service... "); System.out.println("You are number " + youPosition + " in the queue."); while (youPosition != 1) { personName = peopleInQueue.element(); System.out.println(personName + " has purchased a ticket."); peopleInQueue.remove(); youPosition--; System.out.println("You are now number " + youPosition); } System.out.println("You can now purchase your ticket!"); } }
> TicketingService.java:32: error: variable youPosition might not have been initialized
System.out.println("You are number " + youPosition + " in the queue.");
^
1 error
Jimmy246 Sun, Apr 11, 2021 3:50 PM
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 isZadie Smith Tom Sawyer You Louisa Alcottthe output isWelcome 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...
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...
10.14 LAB: Instrument information (derived classes)Given main() and the Instrument class, define a derived class, StringInstrument, for string instruments.Ex. If the input is:Drums Zildjian 2015 2500 Guitar Gibson 2002 1200 6 19the output is:Instrument Information: Name: Drums Manufacturer: Zildjian Year built: 2015 Cost: 2500 Instrument Information: Name: Guitar Manufacturer: Gibson Year built: 2002 Cost: 1200 Number of strings: 6 Number of frets: 19InstrumentInformation.javaimport java.util.Scanner; public class InstrumentInformation { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); Instrument myInstrument = new Instrument(); StringInstrument myStringInstrument = new StringInstrument(); String instrumentName, manufacturerName, stringInstrumentName, stringManufacturer; int yearBuilt, cost, stringYearBuilt, stringCost, numStrings, numFrets; instrumentName = scnr.nextLine(); manufacturerName = scnr.nextLine(); yearBuilt = scnr.nextInt(); scnr.nextLine(); cost = scnr.nextInt(); scnr.nextLine(); stringInstrumentName = scnr.nextLine(); stringManufacturer = scnr.nextLine(); stringYearBuilt = scnr.nextInt(); stringCost = scnr.nextInt(); numStrings = scnr.nextInt(); numFrets = scnr.nextInt(); myInstrument.setName(instrumentName); myInstrument.setManufacturer(manufacturerName); myInstrument.setYearBuilt(yearBuilt); myInstrument.setCost(cost); myInstrument.printInfo(); myStringInstrument.setName(stringInstrumentName); myStringInstrument.setManufacturer(stringManufacturer); myStringInstrument.setYearBuilt(stringYearBuilt); myStringInstrument.setCost(stringCost); myStringInstrument.setNumOfStrings(numStrings); myStringInstrument.setNumOfFrets(numFrets); myStringInstrument.printInfo(); System.out.println(" Number of strings: " + myStringInstrument.getNumOfStrings()); System.out.println(" Number of frets: " + myStringInstrument.getNumOfFrets()); } }Instrument.javapublic class Instrument { protected String instrumentName; protected String instrumentManufacturer; protected int yearBuilt, cost; public void setName(String userName) {...
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...
10.15 LAB: Book information (overriding member methods)Given main() and a base Book class, define a derived class called Encyclopedia. Within the derived Encyclopedia class, define a printInfo() method that overrides the Book class' printInfo() method by printing not only the title, author, publisher, and publication date, but also the edition and number of volumes.Ex. If the input is:The Hobbit J. R. R. Tolkien George Allen & Unwin 21 September 1937 The Illustrated Encyclopedia of the Universe James W. Guthrie Watson-Guptill 2001 2nd 1the output is:Book Information: Book Title: The Hobbit Author: J. R. R. Tolkien Publisher: George Allen & Unwin Publication Date: 21 September 1937 Book Information: Book Title: The Illustrated Encyclopedia of the Universe Author: James W. Guthrie Publisher: Watson-Guptill Publication Date: 2001 Edition: 2nd Number of Volumes: 1Note: Indentations use 3 spaces.BookInformation.javaimport java.util.Scanner; public class BookInformation { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); Book myBook = new Book();...
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...
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...
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...
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...
After dinner with Alexander and Elizabeth we notice that Alexander is mixing some herbs as a medication for Elizabeth which eases her pain and helps her sleep. Once the medicine is administered we begin small talk with Alexander. During the conversation he tells us the story about how his mother and father were hopelessly in love and were lucky enough to die side by side protecting the things they loved most, their children. In the middle of the story we...
> When i entered the code, i got this:
TicketingService.java:32: error: variable youPosition might not have been initialized
System.out.println("You are number " + youPosition + " in the queue.");
^
1 error
Jimmy246 Sun, Apr 11, 2021 3:49 PM