|
@@ -19,6 +19,18 @@ public class TicketMachine
|
19
|
19
|
private int total;
|
20
|
20
|
|
21
|
21
|
/**
|
|
22
|
+ * Create a machine that issues tickets of price = 1000.
|
|
23
|
+ * Note that the price must be greater than zero, and there
|
|
24
|
+ * are no checks to ensure this.
|
|
25
|
+ */
|
|
26
|
+ public TicketMachine()
|
|
27
|
+ {
|
|
28
|
+ price = 1000;
|
|
29
|
+ balance = 0;
|
|
30
|
+ total = 0;
|
|
31
|
+ }
|
|
32
|
+
|
|
33
|
+ /**
|
22
|
34
|
* Create a machine that issues tickets of the given price.
|
23
|
35
|
* Note that the price must be greater than zero, and there
|
24
|
36
|
* are no checks to ensure this.
|
|
@@ -30,6 +42,11 @@ public class TicketMachine
|
30
|
42
|
total = 0;
|
31
|
43
|
}
|
32
|
44
|
|
|
45
|
+ public void setPrice(int ticketCost)
|
|
46
|
+ {
|
|
47
|
+ price = ticketCost;
|
|
48
|
+ }
|
|
49
|
+
|
33
|
50
|
/**
|
34
|
51
|
* Return the price of a ticket.
|
35
|
52
|
*/
|
|
@@ -48,12 +65,45 @@ public class TicketMachine
|
48
|
65
|
}
|
49
|
66
|
|
50
|
67
|
/**
|
|
68
|
+ * Return the amount of money already inserted for the
|
|
69
|
+ * next ticket.
|
|
70
|
+ */
|
|
71
|
+ public int getTotal()
|
|
72
|
+ {
|
|
73
|
+ return total;
|
|
74
|
+ }
|
|
75
|
+
|
|
76
|
+ /**
|
51
|
77
|
* Receive an amount of money in cents from a customer.
|
52
|
78
|
*/
|
53
|
79
|
public void insertMoney(int amount)
|
54
|
80
|
{
|
55
|
81
|
balance = balance + amount;
|
56
|
82
|
}
|
|
83
|
+
|
|
84
|
+ /**
|
|
85
|
+ * Print a message prompting the user to insert correct amount
|
|
86
|
+ */
|
|
87
|
+ public void prompt()
|
|
88
|
+ {
|
|
89
|
+ System.out.println("Please insert the correct amount of money.");
|
|
90
|
+ }
|
|
91
|
+
|
|
92
|
+ /**
|
|
93
|
+ * Print a message letting the user know the ticket amount
|
|
94
|
+ */
|
|
95
|
+ public void showPrice()
|
|
96
|
+ {
|
|
97
|
+ System.out.println("The price of a ticket is " + price + " cents.");
|
|
98
|
+ }
|
|
99
|
+
|
|
100
|
+ /**
|
|
101
|
+ * Print a message letting the user know the ticket amount
|
|
102
|
+ */
|
|
103
|
+ public void empty()
|
|
104
|
+ {
|
|
105
|
+ total=0;
|
|
106
|
+ }
|
57
|
107
|
|
58
|
108
|
/**
|
59
|
109
|
* Print a ticket.
|