-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPearls
124 lines (104 loc) · 3.49 KB
/
Pearls
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
import java.util.Scanner;
public class Pearls {
// use the following Scanner variable and object to collect any necessary user input
public static Scanner scnr = new Scanner(System.in);
public static void main(String[] args) {
// make no changes to the code in this main method
double totalRegisterAmount =getAllTableOrders();
System.out.printf("ticket totals + tax for the entire day: $%.2f\n", totalRegisterAmount);
}
public static double getAllTableOrders() {
double registerTotal = 0.0;
while (moreTablesToServe()) {
double tableTotal = getTableOrder();
registerTotal += tableTotal;
}
return registerTotal;
}
public static boolean moreTablesToServe() {
System.out.print("Another table (\'yes\' or \'no\')? ");
String choice = scnr.next();
boolean table = choice.equals("yes");
return table;
}
public static double getTableOrder() {
double tableTotal = 0.0;
int numDiners = getNumberOfDinersAtTable();
while (numDiners > 0) {
double dinerTotal = getDinersOrder();
tableTotal += dinerTotal;
numDiners --;
}
double taxAmount = tableTotal * 0.08;
System.out.printf("Table total: %.2f\n", tableTotal);
System.out.printf("Tax amount: %.2f\n", taxAmount);
displaySuggestedTipAmounts(tableTotal);
return tableTotal + taxAmount;
}
public static double getDinersOrder() {
double orderTotal = 0.0;
displayMenu();
while (dinerWantsAnotherItem()) {
int choice = getMenuChoice();
double price = getPriceOfMenuChoice(choice);
orderTotal += price;
}
return orderTotal;
}
public static int getNumberOfDinersAtTable() {
System.out.print("Enter number of diners at this table : ");
int num = scnr.nextInt();
return num;
}
public static void displaySuggestedTipAmounts(double cost) {
System.out.printf("10%% tip: %.2f\n", (cost * 0.1) );
System.out.printf("15%% tip: %.2f\n", (cost * 0.15) );
System.out.printf("20%% tip: %.2f\n", (cost * 0.2) );
System.out.printf("25%% tip: %.2f\n", (cost * 0.25) );
}
public static void displayMenu() {
System.out.println("1) eggs $3.25");
System.out.println("2) bacon $4.00");
System.out.println("3) pancakes $2.50");
System.out.println("4) orange juice $1.25");
System.out.println("5) oatmeal $3.99");
System.out.println("6) milk $1.25");
System.out.println("7) donut $2.00");
}
public static boolean dinerWantsAnotherItem() {
System.out.print("Another item (\'yes\' or \'no\')?");
String answer = scnr.next();
boolean result = answer.equals("yes");
return result;
}
public static int getMenuChoice() {
System.out.print("Enter a menu choice : ");
int choice = scnr.nextInt();
return choice;
}
public static double getPriceOfMenuChoice(int choice) {
double price = 0.0;
if (choice == 1) {
price = 3.25;
}
if (choice == 2) {
price = 4.00;
}
if (choice == 3) {
price = 2.50;
}
if (choice == 4) {
price = 1.25;
}
if (choice == 5) {
price = 3.99;
}
if (choice == 6) {
price = 1.25;
}
if (choice == 7) {
price = 2.00;
}
return price;
}
}