-
Notifications
You must be signed in to change notification settings - Fork 0
/
qb266.java
72 lines (60 loc) · 2.73 KB
/
qb266.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* QB-266:
In my restaurant I used to manage it well as per the order. I never want to skip any order
from the customer. So I prepare a rule: When I get the order I add it in the last of my cook
queue. And when the order is ready I used to pick it up from the first of the cook queue.
So, write a java program with class Restaurant. Create a queue cook which contains item
names. Ask user weather he wants to Order or take food. If user press 1 then ask for the
name of the item and it should be added in the cook queue.
If user press 2 then The first item from the queue should be removed from the queue.
If user press 3 then he can see the items of the queue. If user press 4 then he should move
out from the Restaurant
*/
import java.util.*;
class Restaurant {
public static void main(String[] args) {
ArrayDeque<String> cook = new ArrayDeque<>();
Scanner sc = new Scanner(System.in);
int choice;
do {
System.out.println("Enter Your Choice: ");
System.out.println("1) To Order Food \n 2) To TakeAway Food \n 3) Display Your Ordered Items. \n 4) Exit ");
choice = sc.nextInt();
sc.nextLine();
switch (choice) {
case 1:
System.out.println("Enter Food Name you want to order : ");
String fname = sc.nextLine();
cook.addLast(fname);
System.out.println("Ordered Succesfully: " + fname);
System.out.println("Preparing your: " + fname);
break;
case 2:
if (!cook.isEmpty()) {
String food = cook.pollFirst();
System.out.println("Your " + food + " is Prepared.");
System.out.println("TakeAway Successfully !!");
} else {
System.out.println("You have not Ordered Anything..");
}
break;
case 3:
if (cook.isEmpty()) {
System.out.println("Order List is Empty..");
} else {
System.out.println("...Your Order List.. in Queue");
int Number = 1;
for (String ss : cook) {
System.out.println(Number++ + "." + ss);
}
}
break;
case 4:
System.out.println("Thank You For Choosing our Restaurant");
break;
default:
System.out.println("Invalid Choice !!");
break;
}
} while (choice != 4);
}
}