|
@@ -9,7 +9,7 @@
|
9
|
9
|
* @author David J. Barnes and Michael Kolling
|
10
|
10
|
* @version 2008.03.30
|
11
|
11
|
*/
|
12
|
|
-public class TicketMachine
|
|
12
|
+ public class TicketMachine
|
13
|
13
|
{
|
14
|
14
|
// The price of a ticket from this machine.
|
15
|
15
|
private int price;
|
|
@@ -25,9 +25,18 @@ public class TicketMachine
|
25
|
25
|
*/
|
26
|
26
|
public TicketMachine(int ticketCost)
|
27
|
27
|
{
|
28
|
|
- price = ticketCost;
|
29
|
|
- balance = 0;
|
30
|
|
- total = 0;
|
|
28
|
+ price = ticketCost;
|
|
29
|
+ balance = 0;
|
|
30
|
+ total = 0;
|
|
31
|
+
|
|
32
|
+ }
|
|
33
|
+
|
|
34
|
+ public TicketMachine()
|
|
35
|
+ {
|
|
36
|
+ price = 700;
|
|
37
|
+ balance = 0;
|
|
38
|
+ total = 0;
|
|
39
|
+
|
31
|
40
|
}
|
32
|
41
|
|
33
|
42
|
/**
|
|
@@ -37,6 +46,10 @@ public class TicketMachine
|
37
|
46
|
{
|
38
|
47
|
return price;
|
39
|
48
|
}
|
|
49
|
+
|
|
50
|
+ public void setPrice(int newPrice) {
|
|
51
|
+ price = newPrice;
|
|
52
|
+ }
|
40
|
53
|
|
41
|
54
|
/**
|
42
|
55
|
* Return the amount of money already inserted for the
|
|
@@ -46,6 +59,14 @@ public class TicketMachine
|
46
|
59
|
{
|
47
|
60
|
return balance;
|
48
|
61
|
}
|
|
62
|
+
|
|
63
|
+ public void prompt() {
|
|
64
|
+ System.out.println("Please insert the correct amount of money");
|
|
65
|
+ }
|
|
66
|
+
|
|
67
|
+ public void showPrice() {
|
|
68
|
+ System.out.println("The price of a ticket is " + price + " cents.");
|
|
69
|
+ }
|
49
|
70
|
|
50
|
71
|
/**
|
51
|
72
|
* Receive an amount of money in cents from a customer.
|
|
@@ -54,6 +75,10 @@ public class TicketMachine
|
54
|
75
|
{
|
55
|
76
|
balance = balance + amount;
|
56
|
77
|
}
|
|
78
|
+
|
|
79
|
+ public void empty() {
|
|
80
|
+ total = 0;
|
|
81
|
+ }
|
57
|
82
|
|
58
|
83
|
/**
|
59
|
84
|
* Print a ticket.
|