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