|
@@ -17,7 +17,17 @@ 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
|
+
|
|
21
|
+ private int status;
|
|
22
|
+
|
|
23
|
+ private int score;
|
20
|
24
|
|
|
25
|
+ public TicketMachine() {
|
|
26
|
+ price = 1000;
|
|
27
|
+ balance = 0;
|
|
28
|
+ total = 0;
|
|
29
|
+ }
|
|
30
|
+
|
21
|
31
|
/**
|
22
|
32
|
* Create a machine that issues tickets of the given price.
|
23
|
33
|
* Note that the price must be greater than zero, and there
|
|
@@ -37,6 +47,10 @@ public class TicketMachine
|
37
|
47
|
{
|
38
|
48
|
return price;
|
39
|
49
|
}
|
|
50
|
+
|
|
51
|
+ public void setPrice(int ticketCost) {
|
|
52
|
+ price = ticketCost;
|
|
53
|
+ }
|
40
|
54
|
|
41
|
55
|
/**
|
42
|
56
|
* Return the amount of money already inserted for the
|
|
@@ -46,6 +60,10 @@ public class TicketMachine
|
46
|
60
|
{
|
47
|
61
|
return balance;
|
48
|
62
|
}
|
|
63
|
+
|
|
64
|
+ public int getTotal() {
|
|
65
|
+ return total;
|
|
66
|
+ }
|
49
|
67
|
|
50
|
68
|
/**
|
51
|
69
|
* Receive an amount of money in cents from a customer.
|
|
@@ -54,7 +72,33 @@ public class TicketMachine
|
54
|
72
|
{
|
55
|
73
|
balance = balance + amount;
|
56
|
74
|
}
|
57
|
|
-
|
|
75
|
+
|
|
76
|
+ /**
|
|
77
|
+ * Increase score by the give number of points.
|
|
78
|
+ */
|
|
79
|
+ public void increase(int points) {
|
|
80
|
+ score += points;
|
|
81
|
+ }
|
|
82
|
+
|
|
83
|
+ /**
|
|
84
|
+ * Reduce price by the given amount.
|
|
85
|
+ */
|
|
86
|
+ public void discount(int amount) {
|
|
87
|
+ price -= amount;
|
|
88
|
+ }
|
|
89
|
+
|
|
90
|
+ public void prompt() {
|
|
91
|
+ System.out.println("Please insert the correct amount of money.");
|
|
92
|
+ }
|
|
93
|
+
|
|
94
|
+ public void showPrice() {
|
|
95
|
+ System.out.println("The price of a ticket is " + price + " cents.");
|
|
96
|
+ }
|
|
97
|
+
|
|
98
|
+ public void empty() {
|
|
99
|
+ total = 0;
|
|
100
|
+ }
|
|
101
|
+
|
58
|
102
|
/**
|
59
|
103
|
* Print a ticket.
|
60
|
104
|
* Update the total collected and
|
|
@@ -74,5 +118,16 @@ public class TicketMachine
|
74
|
118
|
total = total + balance;
|
75
|
119
|
// Clear the balance.
|
76
|
120
|
balance = 0;
|
|
121
|
+ }
|
|
122
|
+
|
|
123
|
+ public class Student {
|
|
124
|
+
|
|
125
|
+ }
|
|
126
|
+
|
|
127
|
+ public class LabClass {
|
|
128
|
+
|
77
|
129
|
}
|
78
|
130
|
}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|