I don\'t understand!!! please comment each line so I know what\'s going on. EGR
ID: 3598106 • Letter: I
Question
I don't understand!!! please comment each line so I know what's going on.
EGR 140: Computer Programming Assignment # 12: Assigned: Wednesday. 18 October 2017 Due Monday, 23 October 2017 Points: 20 Write an erfree Java programto do the following things. This program approximates the waiting list for a seat at a restaurant. There are several people who arrive simultaneously and wam to eat "ight away" .The progrem shauld prampt the user to input a graup of cherecters (a sring). The chers will refer ta peaple's rarres and will be entereds ward nemes for eath group waitin. There will be exactly 5 rarres that need tobe entered inta the list. The longest neme il beless h 30 cherecters long .Sart the nares into alphabetical order -After all of the names have been eered, the program should promp the uer to inp a name. After the name has been entered, the programshould conduct a search of the list looking for the name o If the name is on the list, then the programprims a message with the name and specifies how many names are ahead of it on the list. o If the name is nct on the list, then the programshould print a kind message that says that customer is oun of luck and should check into eating fast food instead. o The program should continue to prompt for names on the list till the user inputs "done" .At the end, the progamshculd print a friendy ressege (aptianal) .The finlsearch reeds to be repeated till the user inputs "over". The search can be a linear search the list is very shart) r a binary search. Sarple auput IInput a name: washington Input a name: adams Input a name: jofferson Input a name: monroo IInput a name: herf · Sorted list adamsExplanation / Answer
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class RestaurantSeatReservation {
public static void main(String[] args) {
//Create a waitingListOfUsers array with size 5
String waitingListOfUsers[] = new String[5];
Scanner sc = new Scanner(System.in);
String name;
//Read list of users who are waiting for queue
for(int i=0;i<waitingListOfUsers.length;i++) {
System.out.print("Input a name: ");
waitingListOfUsers[i] = sc.next();
}
//Form a sorted list from input
for(int i=0;i<waitingListOfUsers.length-1;i++) {
for(int j=i+1;j<waitingListOfUsers.length;j++) {
if(waitingListOfUsers[i].compareTo(waitingListOfUsers[j])>0) {
String temp = waitingListOfUsers[i];
waitingListOfUsers[i] = waitingListOfUsers[j];
waitingListOfUsers[j] = temp;
}
}
}
//Display sorted list
System.out.println("Sorted List:");
for(int i=0;i<waitingListOfUsers.length;i++) {
System.out.println(waitingListOfUsers[i]);
}
//Read user name and find how many are ahead of list
//If no one ahead of list , you are ready serve for the order
//if done is entered quit the program
while(true) {
System.out.print(" Enter a name: ");
name = sc.next();
//Check for done
if(name.equalsIgnoreCase("done")) {
System.out.println("Thank you! Please visit again!");
break;
}
boolean isFound = false;
//Check the given name exist in the list and find the ahead list
List<String> aheadList = new ArrayList<String>();
for(int i=0;i<waitingListOfUsers.length;i++) {
if(name.equalsIgnoreCase(waitingListOfUsers[i])) {
isFound = true;
break;
}
aheadList.add(waitingListOfUsers[i]);
}
if(isFound) {
if(aheadList.size()==0) {
System.out.println("You are ready to serve!");
} else {
System.out.println("Below names are ahead of you, Please wait for your turn!");
System.out.println(aheadList);
}
} else {
System.out.println("User name not found in list!");
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.