|
@@ -6,11 +6,10 @@
|
6
|
6
|
* to insert enough money before trying to print a ticket.
|
7
|
7
|
* It also assumes that users enter sensible amounts.
|
8
|
8
|
*
|
9
|
|
- * @author David J. Barnes and Michael Kolling
|
10
|
|
- * @version 2008.03.30
|
|
9
|
+ * @author James Seo
|
|
10
|
+ * @version 2018.05.24
|
11
|
11
|
*/
|
12
|
|
-public class TicketMachine
|
13
|
|
-{
|
|
12
|
+public class TicketMachine {
|
14
|
13
|
// The price of a ticket from this machine.
|
15
|
14
|
private int price;
|
16
|
15
|
// The amount of money entered by a customer so far.
|
|
@@ -23,8 +22,7 @@ public class TicketMachine
|
23
|
22
|
* Note that the price must be greater than zero, and there
|
24
|
23
|
* are no checks to ensure this.
|
25
|
24
|
*/
|
26
|
|
- public TicketMachine(int ticketCost)
|
27
|
|
- {
|
|
25
|
+ public TicketMachine(int ticketCost) {
|
28
|
26
|
price = ticketCost;
|
29
|
27
|
balance = 0;
|
30
|
28
|
total = 0;
|
|
@@ -33,8 +31,7 @@ public class TicketMachine
|
33
|
31
|
/**
|
34
|
32
|
* Return the price of a ticket.
|
35
|
33
|
*/
|
36
|
|
- public int getPrice()
|
37
|
|
- {
|
|
34
|
+ public int getPrice() {
|
38
|
35
|
return price;
|
39
|
36
|
}
|
40
|
37
|
|
|
@@ -42,19 +39,41 @@ public class TicketMachine
|
42
|
39
|
* Return the amount of money already inserted for the
|
43
|
40
|
* next ticket.
|
44
|
41
|
*/
|
45
|
|
- public int getBalance()
|
46
|
|
- {
|
47
|
|
- return balance;
|
|
42
|
+ public int getBalance() {
|
|
43
|
+ return balance;
|
48
|
44
|
}
|
49
|
45
|
|
50
|
46
|
/**
|
51
|
47
|
* Receive an amount of money in cents from a customer.
|
52
|
48
|
*/
|
53
|
|
- public void insertMoney(int amount)
|
54
|
|
- {
|
|
49
|
+ public void insertMoney(int amount) {
|
55
|
50
|
balance = balance + amount;
|
56
|
51
|
}
|
|
52
|
+
|
|
53
|
+ public int getTotal() {
|
|
54
|
+ return total;
|
|
55
|
+ }
|
|
56
|
+ public void getPrompt() {
|
|
57
|
+ System.out.println("Please insert the correct amount of money.");
|
|
58
|
+ }
|
|
59
|
+ public void showPrice(){
|
|
60
|
+ System.out.println("# " + price + " cents.");
|
|
61
|
+
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+ public void setEmpty(){
|
|
65
|
+ total = 0;
|
|
66
|
+
|
|
67
|
+ }
|
|
68
|
+ public void setPrice(int newPrice){
|
|
69
|
+
|
|
70
|
+ price = newPrice;
|
|
71
|
+ }
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
57
|
75
|
|
|
76
|
+
|
58
|
77
|
/**
|
59
|
78
|
* Print a ticket.
|
60
|
79
|
* Update the total collected and
|
|
@@ -74,5 +93,6 @@ public class TicketMachine
|
74
|
93
|
total = total + balance;
|
75
|
94
|
// Clear the balance.
|
76
|
95
|
balance = 0;
|
|
96
|
+
|
77
|
97
|
}
|
78
|
98
|
}
|