|
@@ -9,23 +9,29 @@
|
9
|
9
|
* @author David J. Barnes and Michael Kolling
|
10
|
10
|
* @version 2008.03.30
|
11
|
11
|
*/
|
12
|
|
-public class TicketMachine
|
|
12
|
+class TicketMachine
|
13
|
13
|
{
|
14
|
14
|
// The price of a ticket from this machine.
|
15
|
15
|
private int price;
|
16
|
16
|
// The amount of money entered by a customer so far.
|
17
|
|
- private int balance;
|
|
17
|
+
|
18
|
18
|
// The total amount of money collected by this machine.
|
19
|
19
|
private int total;
|
|
20
|
+ private int balance;
|
|
21
|
+ //private int status;
|
|
22
|
+ private int score;
|
|
23
|
+
|
20
|
24
|
|
21
|
25
|
/**
|
22
|
26
|
* Create a machine that issues tickets of the given price.
|
23
|
27
|
* Note that the price must be greater than zero, and there
|
24
|
28
|
* are no checks to ensure this.
|
25
|
29
|
*/
|
26
|
|
- public TicketMachine(int ticketCost)
|
|
30
|
+ public TicketMachine()
|
27
|
31
|
{
|
28
|
|
- price = ticketCost;
|
|
32
|
+ //int price = ticketCost;
|
|
33
|
+ //this.price = ticketCost;
|
|
34
|
+ price = 1000;
|
29
|
35
|
balance = 0;
|
30
|
36
|
total = 0;
|
31
|
37
|
}
|
|
@@ -55,6 +61,50 @@ public class TicketMachine
|
55
|
61
|
balance = balance + amount;
|
56
|
62
|
}
|
57
|
63
|
|
|
64
|
+ public int getTotal(){
|
|
65
|
+ return total;
|
|
66
|
+ }
|
|
67
|
+
|
|
68
|
+ public void setPrice(int ticketCost){
|
|
69
|
+ price = ticketCost;
|
|
70
|
+ }
|
|
71
|
+
|
|
72
|
+ public void increase(int points){
|
|
73
|
+ score = score + points;
|
|
74
|
+ }
|
|
75
|
+
|
|
76
|
+ public void discount(int amount){
|
|
77
|
+ price = price - amount;
|
|
78
|
+ }
|
|
79
|
+
|
|
80
|
+ public void prompt(){
|
|
81
|
+ System.out.println("Please insert the correct amount of money");
|
|
82
|
+ }
|
|
83
|
+
|
|
84
|
+ public void showPrice(){
|
|
85
|
+ System.out.println("The price of the ticket is " + price + "cents");
|
|
86
|
+ }
|
|
87
|
+
|
|
88
|
+ public void empty(){
|
|
89
|
+ total = 0;
|
|
90
|
+ }
|
|
91
|
+
|
|
92
|
+ public int refundBalance()
|
|
93
|
+ {
|
|
94
|
+ int amountToRefund;
|
|
95
|
+ amountToRefund = balance;
|
|
96
|
+ balance = 0;
|
|
97
|
+ return amountToRefund;
|
|
98
|
+ }
|
|
99
|
+ public int emptyMachine(){
|
|
100
|
+ //int total = 0;
|
|
101
|
+ return total;
|
|
102
|
+
|
|
103
|
+ }
|
|
104
|
+ public int printTicket(){
|
|
105
|
+ int amountLeftToPay = price - balance;
|
|
106
|
+
|
|
107
|
+
|
58
|
108
|
/**
|
59
|
109
|
* Print a ticket.
|
60
|
110
|
* Update the total collected and
|
|
@@ -62,6 +112,7 @@ public class TicketMachine
|
62
|
112
|
*/
|
63
|
113
|
public void printTicket()
|
64
|
114
|
{
|
|
115
|
+
|
65
|
116
|
// Simulate the printing of a ticket.
|
66
|
117
|
System.out.println("##################");
|
67
|
118
|
System.out.println("# The BlueJ Line");
|