|
@@ -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
|
+ class TicketMachine
|
13
|
13
|
{
|
14
|
14
|
// The price of a ticket from this machine.
|
15
|
15
|
private int price;
|
|
@@ -17,26 +17,43 @@ 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;
|
|
24
|
+
|
|
25
|
+ private int discount;
|
20
|
26
|
|
21
|
27
|
/**
|
22
|
28
|
* Create a machine that issues tickets of the given price.
|
23
|
29
|
* Note that the price must be greater than zero, and there
|
24
|
30
|
* are no checks to ensure this.
|
25
|
31
|
*/
|
26
|
|
- public TicketMachine(int ticketCost)
|
|
32
|
+ public TicketMachine()
|
27
|
33
|
{
|
28
|
|
- price = ticketCost;
|
|
34
|
+ price = 1000;
|
29
|
35
|
balance = 0;
|
30
|
36
|
total = 0;
|
31
|
37
|
}
|
|
38
|
+
|
|
39
|
+ public TicketMachine(int cost){
|
|
40
|
+
|
|
41
|
+ price = cost;
|
|
42
|
+ }
|
32
|
43
|
|
33
|
44
|
/**
|
34
|
45
|
* Return the price of a ticket.
|
35
|
46
|
*/
|
36
|
47
|
public int getPrice()
|
37
|
48
|
{
|
38
|
|
- return price;
|
|
49
|
+ return price;
|
39
|
50
|
}
|
|
51
|
+
|
|
52
|
+ public void setPrice(int ticketCost)
|
|
53
|
+ {
|
|
54
|
+ price = ticketCost;
|
|
55
|
+ }
|
|
56
|
+
|
40
|
57
|
|
41
|
58
|
/**
|
42
|
59
|
* Return the amount of money already inserted for the
|
|
@@ -46,6 +63,11 @@ public class TicketMachine
|
46
|
63
|
{
|
47
|
64
|
return balance;
|
48
|
65
|
}
|
|
66
|
+
|
|
67
|
+ public int getTotal()
|
|
68
|
+ {
|
|
69
|
+ return total;
|
|
70
|
+ }
|
49
|
71
|
|
50
|
72
|
/**
|
51
|
73
|
* Receive an amount of money in cents from a customer.
|
|
@@ -54,6 +76,31 @@ public class TicketMachine
|
54
|
76
|
{
|
55
|
77
|
balance = balance + amount;
|
56
|
78
|
}
|
|
79
|
+
|
|
80
|
+ public void empty(int total){
|
|
81
|
+
|
|
82
|
+ total = 0;
|
|
83
|
+ }
|
|
84
|
+
|
|
85
|
+ public void increase(int points){
|
|
86
|
+
|
|
87
|
+ score += points;
|
|
88
|
+ }
|
|
89
|
+
|
|
90
|
+ public void discount(int amount){
|
|
91
|
+
|
|
92
|
+ price -= amount;
|
|
93
|
+ }
|
|
94
|
+
|
|
95
|
+ public void prompt(){
|
|
96
|
+
|
|
97
|
+ System.out.println("Please insert the correct amount of money.");
|
|
98
|
+ }
|
|
99
|
+
|
|
100
|
+ public void showPrice(){
|
|
101
|
+
|
|
102
|
+ System.out.println("The price of a ticket is " + price + " cents.");
|
|
103
|
+ }
|
57
|
104
|
|
58
|
105
|
/**
|
59
|
106
|
* Print a ticket.
|
|
@@ -74,5 +121,12 @@ public class TicketMachine
|
74
|
121
|
total = total + balance;
|
75
|
122
|
// Clear the balance.
|
76
|
123
|
balance = 0;
|
|
124
|
+ int count = 0;
|
|
125
|
+
|
|
126
|
+ int savings = price * discount;
|
|
127
|
+
|
|
128
|
+ int mean = total/count;
|
|
129
|
+
|
|
130
|
+
|
77
|
131
|
}
|
78
|
132
|
}
|