-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimsOrder.java
94 lines (75 loc) · 2.35 KB
/
TimsOrder.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package cafeCheckout;
import java.util.Scanner;
/**
* This TimsOrder class is the super class of Coffee, Donut, Mug and Hat
*
* @author Meet Patel
**/
public class TimsOrder {
// no of the order
private int size;
// name of the order giver
private String name;
// stores the no. of item
private static int item;
// array of timsproduct
static TimsProduct[] p;
// set the name and size
private TimsOrder(String name, int size) {
this.name = name;
this.size = size;
}
// creates an object of Timsorder
public static TimsOrder create() {
System.out.println("Please enter your name: ");
// TODO: Fill in this stub to have a dialog with the user
Scanner sc = new Scanner(System.in);
String name;
name = sc.nextLine();
System.out.println("Please enter how much items do you want? ");
item = sc.nextInt();
p = new TimsProduct[item];
for (int i = 0; i < item; i++) {
System.out.println("Enter your choice of item \n" +
"1. Coffee\n" +
"2. Donut\n" +
"3. Mug\n" +
"4. Hat\n" +
"Your choice: "
);
int choice;
choice = sc.nextInt();
switch (choice) {
case 1:
p[i] = Coffee.create();
break;
case 2:
p[i] = Donut.create();
break;
case 3:
p[i] = Mug.create();
break;
case 4:
p[i] = Hat.create();
break;
default:
System.out.println("Please enter correct choice: ");
break;
}
}
TimsOrder t = new TimsOrder(name, item);
return t;
}
// calculate the amount
public double getAmountDue() {
double price = 0;
for (int i = 0; i < item; i++) {
price += p[i].getRetailPrice();
}
return price;
}
// print the string
public String toString() {
return name ;
}
}