forked from aikumapayi24/Lone
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFoodmenu.java
More file actions
178 lines (142 loc) · 5.53 KB
/
Foodmenu.java
File metadata and controls
178 lines (142 loc) · 5.53 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package restaurantMenu;
import java.util.Scanner;
public class Foodmenu {
public static void main(String[] args) {
// TODO Auto-generated method stub
// Display a header with a welcome
System.out.println( "\n"+" "+"Welcome to Our Restaurant" + "\n"+ "\n"+ "\t" + " " + "Food Menu"+ "\n"+
"--------------------------------------------------------" );
// Create a container to store name of each category
String Category_1 = "Drink";
String Category_2 = "Meal";
String Category_3 = "Desert";
// Display a header of the category with its prices
System.out.println( " "+ Category_1 + "\t price\t" +" "+ Category_2+" "+" price\t" + Category_3 + "\t price\n" +
"--------------------------------------------------------" );
// Create a container to store multiple items of each category and prices
String[] Category_1_item = { "boaba", "wonjo", "Dahar"};
double[] Category_1_prices = { 20, 10, 30 };
String[] Category_2_item = { "plasas", "acheke", "domoda"};
double[] Category_2_prices = { 60, 70, 80 };
String[] Category_3_item = { "chakri", " cake ", "juice " };
double[] Category_3_prices = { 50, 60, 50 };
// use a loop to loop through each category items and prices for it to be displayed in an organised manner
for (int i = 0; i<3; i++ ) {
System.out.println( i+1 +" "+Category_1_item [i] + " " + Category_1_prices [i]+ " "
+ (i+1)+" "+Category_2_item [i] + " " + Category_2_prices [i] + " "
+ (i+1)+" "+Category_3_item [i] + " " + Category_3_prices [i] + " ");
}
// invoke each method in the main
Drink();
Meal();
Desert();
Receipt();
}
// create a variable that can be accessed by each method
static String choice_1 = "",choice_2 = "",choice_3 = "";
static double price_of_choice_1 = 0,price_of_choice_2 = 0,price_of_choice_3 = 0;
static double sum = 0;
// create a method for drink
public static void Drink() {
// get user input for drinks
Scanner input= new Scanner(System.in);
System.out.println( "select an item from drinks");
int item1 = input.nextInt();
// create a container to store items and price for drinks
String[] category_1_items = { "boaba", "wonjo", "Dahar"};
double[] category_1_prices = { 20, 10, 30 };
// use the if condition to verify the user choice of item selected
if(item1 == 1)
{
choice_1 = category_1_items[0];
price_of_choice_1 = category_1_prices[0];
}
else if(item1 == 2)
{
choice_1 = category_1_items[1];
price_of_choice_1 = category_1_prices[1];
}
else if(item1 == 3)
{
choice_1 = category_1_items[2];
price_of_choice_1 = category_1_prices[2];
}else
{
choice_1 = "None";
price_of_choice_1 = 0;
}
sum = sum( sum , price_of_choice_1 );
}
public static void Meal() {
String[] category_2_items = { "plasas", "acheke", "domoda"};
double[] category_2_prices = { 60, 70, 80 };
Scanner input= new Scanner(System.in);
System.out.println( "select an item from Meal");
int item1 = input.nextInt();
if(item1 == 1)
{
choice_2 = category_2_items[0];
price_of_choice_2 = category_2_prices[0];
}
else if(item1 == 2)
{
choice_2 = category_2_items[1];
price_of_choice_2 = category_2_prices[1];
}
else if(item1 == 3)
{
choice_2 = category_2_items[2];
price_of_choice_2 = category_2_prices[2];
}else
{
choice_2 = "None";
price_of_choice_2 = 0;
}
sum = sum ( sum , price_of_choice_2 );
}
public static void Desert() {
String[] category_3_items = { "chakri", " cake ", "juice " };
double[] category_3_prices = { 50, 60, 50 };
Scanner input= new Scanner(System.in);
System.out.println( "select an item from Desert");
int item1 = input.nextInt();
if(item1 == 1)
{
choice_3 = category_3_items[0];
price_of_choice_3 = category_3_prices[0];
}
else if(item1 == 2)
{
choice_3 = category_3_items[1];
price_of_choice_3 = category_3_prices[1];
}
else if(item1 == 3)
{
choice_3 = category_3_items[2];
price_of_choice_3 = category_3_prices[2];
}else
{
choice_3 = "None";
price_of_choice_3 = 0;
}
sum = sum ( sum , price_of_choice_3 );
}
public static double sum(double a, double b)
{
return a+b;
}
public static void Receipt() {
// print out the header of category, item and prices
System.out.println(".................................."
+ "\ncategory"+"\t item "+"\tPrice"
+ "\n.................................");
// Print receipt of selected items, their prices and total
System.out.println( "Drink" + "\t" + "\t"+choice_1 + "\t" + price_of_choice_1 + "\n"
+ "Meal" + "\t" + "\t"+choice_2 + "\t" + price_of_choice_2 + "\n" +
"Desert" + "\t" + "\t"+choice_3 + "\t" + price_of_choice_3 + "\n"
+ ".................................."+
"\nTotal price is " + "\t" + "\t" +sum
+ "\n.................................."
);
}
}