Skip to content

Commit 98cffd0

Browse files
committed
Intergalactic Vending Machine 8.G!!!
1 parent 6e13869 commit 98cffd0

1 file changed

Lines changed: 84 additions & 0 deletions

File tree

ch08/IntergalacticVending.java

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
2+
import java.util.Scanner;
3+
4+
public class IntergalacticVending
5+
{
6+
7+
private static void customerChoice()
8+
{
9+
final int TOTAL_OPTIONS_AVAILABLE = 5;
10+
final int SECRET_NUMBER = 99;
11+
12+
Scanner in = new Scanner(System.in);
13+
int choice = 0;
14+
15+
int[] mealChoice = new int[TOTAL_OPTIONS_AVAILABLE];
16+
17+
18+
19+
20+
while (choice != SECRET_NUMBER && choice <= 4)
21+
{
22+
System.out.print("Enter Choice: ");
23+
choice = in.nextInt();
24+
25+
if (choice == 0)
26+
{
27+
mealChoice[0]++;
28+
printArray(mealChoice);
29+
}
30+
if (choice == 1)
31+
{
32+
mealChoice[1]++;
33+
printArray(mealChoice);
34+
}
35+
else if (choice == 2)
36+
{
37+
mealChoice[2]++;
38+
printArray(mealChoice);
39+
}
40+
else if (choice == 3)
41+
{
42+
mealChoice[3]++;
43+
printArray(mealChoice);
44+
45+
}
46+
else if (choice == 4)
47+
{
48+
mealChoice[4]++;
49+
printArray(mealChoice);
50+
51+
}
52+
else if (choice == SECRET_NUMBER)
53+
{
54+
System.out.println("Goodbye");
55+
printArray(mealChoice);
56+
}
57+
58+
}
59+
60+
}
61+
62+
private static void printArray(int[] meals)
63+
{
64+
System.out.print("{" + meals[0]);
65+
for (int i = 1; i < meals.length; i++)
66+
{
67+
System.out.print(", " + meals[i]);
68+
}
69+
System.out.println("}");
70+
}
71+
72+
public static void main(String[] args)
73+
{
74+
System.out.println("Intergalactic Vending Machine");
75+
System.out.println();
76+
77+
customerChoice();
78+
}
79+
80+
}
81+
82+
83+
84+

0 commit comments

Comments
 (0)