|
@@ -24,12 +24,16 @@ public class TicketMachine
|
24
|
24
|
* Note that the price must be greater than zero, and there
|
25
|
25
|
* are no checks to ensure this.
|
26
|
26
|
*/
|
27
|
|
- public TicketMachine(int ticketCost)
|
28
|
|
- {
|
29
|
|
- int price = ticketCost;
|
|
27
|
+ public TicketMachine(int ticketCost) {
|
|
28
|
+ price = ticketCost;
|
30
|
29
|
balance = 0;
|
31
|
30
|
total = 0;
|
32
|
31
|
}
|
|
32
|
+
|
|
33
|
+ public TicketMachine()
|
|
34
|
+ {
|
|
35
|
+ this(1000);
|
|
36
|
+ }
|
33
|
37
|
|
34
|
38
|
/**
|
35
|
39
|
* Return the price of a ticket.
|
|
@@ -52,6 +56,15 @@ public class TicketMachine
|
52
|
56
|
{
|
53
|
57
|
return total;
|
54
|
58
|
}
|
|
59
|
+
|
|
60
|
+ public void setPrice(int ticketCost)
|
|
61
|
+ {
|
|
62
|
+ price = ticketCost;
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+ public void discount(int amount) {
|
|
66
|
+ price -= amount;
|
|
67
|
+ }
|
55
|
68
|
|
56
|
69
|
/**
|
57
|
70
|
* Receive an amount of money in cents from a customer.
|
|
@@ -81,4 +94,16 @@ public class TicketMachine
|
81
|
94
|
// Clear the balance.
|
82
|
95
|
balance = 0;
|
83
|
96
|
}
|
|
97
|
+
|
|
98
|
+ public void prompt() {
|
|
99
|
+ System.out.println("Please insert the correct amount of money.");
|
|
100
|
+ }
|
|
101
|
+
|
|
102
|
+ public void showPrice() {
|
|
103
|
+ System.out.println("The price of a ticket is " + this.price + " cents.");
|
|
104
|
+ }
|
|
105
|
+
|
|
106
|
+ public void empty() {
|
|
107
|
+ total = 0;
|
|
108
|
+ }
|
84
|
109
|
}
|