Question: import java.util.Scanner; public class CustomersQueue { public static void main(String[] args) { // initiate an ArrayQueue object called customers to represent a waiting queue //
import java.util.Scanner;
public class CustomersQueue {
public static void main(String[] args) {
// initiate an ArrayQueue object called "customers" to represent a waiting queue
// create a scanner
// create a variable "command" to store user's selected option (returned from the method: menu)
// In the while loop as long as the user's option is not 'X'- exit, then continue the iteration
// you may consider using case-switch statement or multiple-if statement
// If user selected option is 'N', then call offer method in ArrayQueue
// If user selected option is 'D', then call peek method in ArrayQueue
// If user selected option is 'R', then call poll method in ArrayQueue
// If user selected option is 'L', then return queue size
//** If user selected option is 'W', then (1)ask user to enter the customer's name (2) call "waitlength" method
// And then display the number of people ahead of user entered customer, or show error message if the customer is not found.
// close the scanner
}
/**
* waitLength method
* @param customers
* @param who
* @return the length of the queue (the number of customers in the queue)
*/
private static int waitLength(ArrayQueue
int count = 0;
for (String e : customers) {
if (e.equals(who)) return count;
count++;
}
return -1;
}
/** * getCustomer method asked user to enter customer's name
* @param scan
* @return user entered customer's name as string
*/
private static String getCustomer(Scanner scan) {
System.out.println("Enter customer name:");
return scan.nextLine().trim();
}
/** * A method called menu: show six options to users: * N - New Customer * D - Display First Customer in Line * R - Remove First Customer in Line * L - Display Line Length * W - Display wait length for specific customer * X - Exit * *
@param scan
* @return user's option: data type is char
*/
private static char menu(Scanner scan) {
//display the six options to the user
// trim the user input option
String next = scan.nextLine().trim();
// create a variable (char type) to store user's selection
// If user entered a valid selection then return the command, otherwise
// display an error message indicating it is invalid selection and display the menu again
return 'X';
// placeholder. return command;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
