|
@@ -17,18 +17,27 @@ 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
|
|
-
|
|
20
|
+ // Excersise 2.15.
|
|
21
|
+ private int status;
|
|
22
|
+
|
|
23
|
+ public TicketMachine(int amount) {
|
|
24
|
+ price = amount;
|
|
25
|
+ balance = 0;
|
|
26
|
+ total = 0;
|
|
27
|
+ }
|
|
28
|
+
|
21
|
29
|
/**
|
22
|
30
|
* Create a machine that issues tickets of the given price.
|
23
|
31
|
* Note that the price must be greater than zero, and there
|
24
|
32
|
* are no checks to ensure this.
|
25
|
33
|
*/
|
26
|
|
- public TicketMachine(int ticketCost)
|
|
34
|
+ public TicketMachine()
|
27
|
35
|
{
|
28
|
|
- price = ticketCost;
|
|
36
|
+ price = 1000;
|
29
|
37
|
balance = 0;
|
30
|
38
|
total = 0;
|
31
|
39
|
}
|
|
40
|
+
|
32
|
41
|
|
33
|
42
|
/**
|
34
|
43
|
* Return the price of a ticket.
|
|
@@ -46,6 +55,17 @@ public class TicketMachine
|
46
|
55
|
{
|
47
|
56
|
return balance;
|
48
|
57
|
}
|
|
58
|
+
|
|
59
|
+ // Excercise 2.24
|
|
60
|
+ public int getTotal()
|
|
61
|
+ {
|
|
62
|
+ return total;
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+ // Excercise 2.30 + 2.41
|
|
66
|
+ public void setPrice(int amount) {
|
|
67
|
+ price = amount;
|
|
68
|
+ }
|
49
|
69
|
|
50
|
70
|
/**
|
51
|
71
|
* Receive an amount of money in cents from a customer.
|
|
@@ -55,6 +75,18 @@ public class TicketMachine
|
55
|
75
|
balance = balance + amount;
|
56
|
76
|
}
|
57
|
77
|
|
|
78
|
+ // Excercise 2.33
|
|
79
|
+ public void prompt()
|
|
80
|
+ {
|
|
81
|
+ System.out.println("Please insert the correct amount of money.");
|
|
82
|
+ }
|
|
83
|
+
|
|
84
|
+ // Excercise 2.34
|
|
85
|
+ public void showPrice()
|
|
86
|
+ {
|
|
87
|
+ System.out.println("The price of a ticket is " + price + " cents.");
|
|
88
|
+ }
|
|
89
|
+
|
58
|
90
|
/**
|
59
|
91
|
* Print a ticket.
|
60
|
92
|
* Update the total collected and
|
|
@@ -75,4 +107,10 @@ public class TicketMachine
|
75
|
107
|
// Clear the balance.
|
76
|
108
|
balance = 0;
|
77
|
109
|
}
|
|
110
|
+
|
|
111
|
+ // Excercise 2.40
|
|
112
|
+ public void empty()
|
|
113
|
+ {
|
|
114
|
+ total = 0;
|
|
115
|
+ }
|
78
|
116
|
}
|