|
@@ -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,17 +17,30 @@ 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
|
+ // The amount of money taken off of a payment
|
|
21
|
+ private int discount;
|
|
22
|
+ // The amount of money being saved by user
|
|
23
|
+ private int saving;
|
|
24
|
+ //The value of total divided by count
|
|
25
|
+ private int mean;
|
|
26
|
+ //the value divided by total to get mean
|
|
27
|
+ private int count;
|
|
28
|
+ private int budget;
|
20
|
29
|
|
21
|
30
|
/**
|
22
|
31
|
* Create a machine that issues tickets of the given price.
|
23
|
32
|
* Note that the price must be greater than zero, and there
|
24
|
33
|
* are no checks to ensure this.
|
25
|
34
|
*/
|
26
|
|
- public TicketMachine(int ticketCost)
|
|
35
|
+ public TicketMachine()
|
27
|
36
|
{
|
28
|
|
- price = ticketCost;
|
|
37
|
+ price = 0;
|
29
|
38
|
balance = 0;
|
30
|
39
|
total = 0;
|
|
40
|
+ discount = (int)(.10);
|
|
41
|
+ mean = 0;
|
|
42
|
+ count = 500;
|
|
43
|
+ budget = 0;
|
31
|
44
|
}
|
32
|
45
|
|
33
|
46
|
/**
|
|
@@ -38,6 +51,11 @@ public class TicketMachine
|
38
|
51
|
return price;
|
39
|
52
|
}
|
40
|
53
|
|
|
54
|
+ public int setPrice(int newPrice)
|
|
55
|
+ {
|
|
56
|
+ return newPrice;
|
|
57
|
+ }
|
|
58
|
+
|
41
|
59
|
/**
|
42
|
60
|
* Return the amount of money already inserted for the
|
43
|
61
|
* next ticket.
|
|
@@ -56,6 +74,14 @@ public class TicketMachine
|
56
|
74
|
}
|
57
|
75
|
|
58
|
76
|
/**
|
|
77
|
+ * Returns total amount of money this machine has collected
|
|
78
|
+ */
|
|
79
|
+ public int getTotal()
|
|
80
|
+ {
|
|
81
|
+ return total;
|
|
82
|
+ }
|
|
83
|
+
|
|
84
|
+ /**
|
59
|
85
|
* Print a ticket.
|
60
|
86
|
* Update the total collected and
|
61
|
87
|
* reduce the balance to zero.
|
|
@@ -69,10 +95,35 @@ public class TicketMachine
|
69
|
95
|
System.out.println("# " + price + " cents.");
|
70
|
96
|
System.out.println("##################");
|
71
|
97
|
System.out.println();
|
72
|
|
-
|
|
98
|
+
|
|
99
|
+ mean = total / count;
|
|
100
|
+ //Update the total combined with discount.
|
|
101
|
+ saving = price * discount;
|
73
|
102
|
// Update the total collected with the balance.
|
74
|
103
|
total = total + balance;
|
75
|
104
|
// Clear the balance.
|
76
|
105
|
balance = 0;
|
|
106
|
+
|
|
107
|
+ if (price > budget){
|
|
108
|
+ System.out.println("Too expensive. Your budget is: " + budget + ".");
|
|
109
|
+ } else {
|
|
110
|
+ System.out.println("Just right.");
|
|
111
|
+ }
|
|
112
|
+ }
|
|
113
|
+
|
|
114
|
+ public void prompt()
|
|
115
|
+ {
|
|
116
|
+ System.out.println("Please insert the correct amount of money.");
|
|
117
|
+ }
|
|
118
|
+
|
|
119
|
+ public void showPrice(int ticketPrice)
|
|
120
|
+ {
|
|
121
|
+ System.out.println("The price of a ticket is " + price + " cents.");
|
|
122
|
+ }
|
|
123
|
+
|
|
124
|
+ public void empty()
|
|
125
|
+ {
|
|
126
|
+ total = 0;
|
77
|
127
|
}
|
78
|
|
-}
|
|
128
|
+
|
|
129
|
+}
|