forked from aikumapayi24/Lone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
food menu
156 lines (122 loc) · 4.3 KB
/
food menu
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
package Foodmenu;
import java.util.Scanner;
public class Food {
public static void main(String[] args)
{
// declare strings for each category
String category_1 = "Food";
String category_2 = "Drink";
String category_3 = "Dinner";
// create an Array of of each strings of food, drink, dinner
String[] category_1_items = {"Bread","Egg","Cake"};
double[] category_1_prices = { 12, 10 , 15 };
String[] category_2_items = {"soda","Water","Juice"};
double[] category_2_prices = { 35, 40 , 25 };
String[] category_3_items = {"Domoda","Jollof","Mbahal"};
double[] category_3_prices = { 30, 40 , 50 };
// print out the category headers
System.out.println(" "+category_1+"\tPrice\t"+category_2+"\tPrice\t"+category_3+"\tPrice\n");
// loop through the array of category items and prices to show each category with its items and price
for(int i = 0; i < 3 ; i++)
{
System.out.println( i+1 +" "+ category_1_items [i] + "\t" + category_1_prices [i] + "\t"
+ (i+1) +" "+ category_2_items [i] + "\t" + category_2_prices [i] + "\t"
+ (i+1) +" "+category_3_items [i] + "\t" + category_3_prices [i]);
}
// Scanner class use to enter the input of each selected item (category1)
Scanner input= new Scanner(System.in);
System.out.println( "select an item from food");
int item1 = input.nextInt();
// Declare variables to hold the related item and it's price to the user input
String choice_1 = "";
double price_of_choice_1 = 0;
double sum = 0;
// Verify user choice of item within category 1
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;
}
// Scanner class use to enter the input of each selected item (category1)
System.out.println( "select an item from drinks");
int item2 = input.nextInt();
// Declare variables to hold the related item and it's price to the user input
String choice_2 = "";
double price_of_choice_2 = 0;
// Verify user choice of item within category 2
if(item2 == 1)
{
choice_2 = category_2_items[0];
price_of_choice_2 = category_2_prices[0];
}
else if(item2 == 2)
{
choice_2 = category_2_items[1];
price_of_choice_2 = category_2_prices[1];
}
else if(item2 == 3)
{
choice_2 = category_2_items[2];
price_of_choice_2 = category_2_prices[2];
}else
{
choice_2 = "None";
price_of_choice_2 = 0;
}
// Scanner class use to enter the input of each selected item (category1)
System.out.println( "select an item from dinner");
int item3 = input.nextInt();
// Declare variables to hold the related item and it's price to the user input
String choice_3 = "";
double price_of_choice_3 = 0;
//double sum = 0;
// Verify user choice of item within category 3
if(item3 == 1)
{
choice_3 = category_3_items[0];
price_of_choice_3 = category_3_prices[0];
}
else if(item3 == 2)
{
choice_3 = category_3_items[1];
price_of_choice_3 = category_3_prices[1];
}
else if(item3 == 3)
{
choice_3 = category_3_items[2];
price_of_choice_3 = category_3_prices[2];
}else
{
choice_3 = "None";
price_of_choice_3 = 0;
}
// add the sum of all selected item and string to print out
sum= sum + price_of_choice_1 + price_of_choice_2 + price_of_choice_3;
// 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( category_1 + "\t" + "\t"+choice_1 + "\t" + price_of_choice_1 + "\n"
+ category_2 + "\t" + "\t"+choice_2 + "\t" + price_of_choice_2 + "\n" +
category_3 + "\t" + "\t"+choice_3 + "\t" + price_of_choice_3 + "\n"
+ ".................................."+
"\nTotal price is " + "\t" + "\t" +sum
+ "\n.................................."
);
}
}