|
@@ -1,38 +1,34 @@
|
1
|
|
-/**
|
2
|
|
- * TicketMachine models a naive ticket machine that issues
|
3
|
|
- * flat-fare tickets.
|
4
|
|
- * The price of a ticket is specified via the constructor.
|
5
|
|
- * It is a naive machine in the sense that it trusts its users
|
6
|
|
- * to insert enough money before trying to print a ticket.
|
7
|
|
- * It also assumes that users enter sensible amounts.
|
8
|
|
- *
|
9
|
|
- * @author David J. Barnes and Michael Kolling
|
10
|
|
- * @version 2008.03.30
|
11
|
|
- */
|
|
1
|
+
|
12
|
2
|
public class TicketMachine
|
13
|
3
|
{
|
14
|
|
- // The price of a ticket from this machine.
|
|
4
|
+
|
15
|
5
|
private int price;
|
16
|
|
- // The amount of money entered by a customer so far.
|
|
6
|
+
|
17
|
7
|
private int balance;
|
18
|
|
- // The total amount of money collected by this machine.
|
|
8
|
+
|
19
|
9
|
private int total;
|
20
|
|
-
|
|
10
|
+
|
|
11
|
+ private int score;
|
21
|
12
|
/**
|
22
|
13
|
* Create a machine that issues tickets of the given price.
|
23
|
14
|
* Note that the price must be greater than zero, and there
|
24
|
15
|
* are no checks to ensure this.
|
25
|
16
|
*/
|
26
|
|
- public TicketMachine(int ticketCost)
|
|
17
|
+ public TicketMachine()
|
27
|
18
|
{
|
28
|
|
- price = ticketCost;
|
|
19
|
+ price = 1000;
|
29
|
20
|
balance = 0;
|
30
|
21
|
total = 0;
|
31
|
22
|
}
|
32
|
|
-
|
33
|
|
- /**
|
34
|
|
- * Return the price of a ticket.
|
35
|
|
- */
|
|
23
|
+
|
|
24
|
+ public TicketMachine(int ticketCost){}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+ public void setPrie(int ticketCost){
|
|
28
|
+ price = ticketCost;
|
|
29
|
+ }
|
|
30
|
+
|
|
31
|
+
|
36
|
32
|
public int getPrice()
|
37
|
33
|
{
|
38
|
34
|
return price;
|
|
@@ -47,6 +43,23 @@ public class TicketMachine
|
47
|
43
|
return balance;
|
48
|
44
|
}
|
49
|
45
|
|
|
46
|
+ public void increase(int points){
|
|
47
|
+ score = score + points;
|
|
48
|
+ }
|
|
49
|
+
|
|
50
|
+ public void discount(int amount){
|
|
51
|
+
|
|
52
|
+ price = price - amount;
|
|
53
|
+ }
|
|
54
|
+
|
|
55
|
+ public void promot(){
|
|
56
|
+ System.out.println("Please insert the correct amount of money.");
|
|
57
|
+ }
|
|
58
|
+
|
|
59
|
+ public void showPrice(){
|
|
60
|
+ System.out.println("The price of a ticke is" + price + "cents");
|
|
61
|
+ }
|
|
62
|
+
|
50
|
63
|
/**
|
51
|
64
|
* Receive an amount of money in cents from a customer.
|
52
|
65
|
*/
|
|
@@ -54,7 +67,15 @@ public class TicketMachine
|
54
|
67
|
{
|
55
|
68
|
balance = balance + amount;
|
56
|
69
|
}
|
57
|
|
-
|
|
70
|
+
|
|
71
|
+ public int getTotal(int amount){
|
|
72
|
+ return total;
|
|
73
|
+ }
|
|
74
|
+
|
|
75
|
+ public void empty(){
|
|
76
|
+ total = 0;
|
|
77
|
+ }
|
|
78
|
+
|
58
|
79
|
/**
|
59
|
80
|
* Print a ticket.
|
60
|
81
|
* Update the total collected and
|