|
@@ -0,0 +1,117 @@
|
|
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
|
+ */
|
|
12
|
+public class Student{
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+ public class LabClass{
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+ }
|
|
19
|
+
|
|
20
|
+ public class TicketMachine
|
|
21
|
+ {
|
|
22
|
+ // The price of a ticket from this machine.
|
|
23
|
+ private int price;
|
|
24
|
+ int status;
|
|
25
|
+ // The amount of money entered by a customer so far.
|
|
26
|
+ private int balance;
|
|
27
|
+ // The total amount of money collected by this machine.
|
|
28
|
+ private int total;
|
|
29
|
+
|
|
30
|
+ public String Pet(String petsName){
|
|
31
|
+ petsName = "Cujo";
|
|
32
|
+ return petsName;
|
|
33
|
+ }
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+ /**
|
|
37
|
+ * Create a machine that issues tickets of the given price.
|
|
38
|
+ * Note that the price must be greater than zero, and there
|
|
39
|
+ * are no checks to ensure this.
|
|
40
|
+ */
|
|
41
|
+ public TicketMachine()
|
|
42
|
+ {
|
|
43
|
+ price = 1000;
|
|
44
|
+ balance = 0;
|
|
45
|
+ total = 0;
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+ }
|
|
49
|
+
|
|
50
|
+ public void setPrice()
|
|
51
|
+ {
|
|
52
|
+ getPrice();
|
|
53
|
+ }
|
|
54
|
+
|
|
55
|
+ public void prompt()
|
|
56
|
+ {
|
|
57
|
+ System.out.println("Please insert the correct amount of money.");
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ public void showPrice()
|
|
61
|
+ {
|
|
62
|
+ System.out.println("The price of a ticket " + price +" cents." );
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+ public void empty()
|
|
66
|
+ {
|
|
67
|
+ total = 0;
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+ /**
|
|
72
|
+ * Return the price of a ticket.
|
|
73
|
+ */
|
|
74
|
+ public int getPrice()
|
|
75
|
+ {
|
|
76
|
+ return price;
|
|
77
|
+ }
|
|
78
|
+
|
|
79
|
+ /**
|
|
80
|
+ * Return the amount of money already inserted for the
|
|
81
|
+ * next ticket.
|
|
82
|
+ */
|
|
83
|
+ public int getBalance()
|
|
84
|
+ {
|
|
85
|
+ return balance;
|
|
86
|
+ }
|
|
87
|
+
|
|
88
|
+ /**
|
|
89
|
+ * Receive an amount of money in cents from a customer.
|
|
90
|
+ */
|
|
91
|
+ public void insertMoney(int amount)
|
|
92
|
+ {
|
|
93
|
+ balance = balance + amount;
|
|
94
|
+ }
|
|
95
|
+
|
|
96
|
+ /**
|
|
97
|
+ * Print a ticket.
|
|
98
|
+ * Update the total collected and
|
|
99
|
+ * reduce the balance to zero.
|
|
100
|
+ */
|
|
101
|
+ public void printTicket()
|
|
102
|
+ {
|
|
103
|
+ // Simulate the printing of a ticket.
|
|
104
|
+ System.out.println("##################");
|
|
105
|
+ System.out.println("# The BlueJ Line");
|
|
106
|
+ System.out.println("# Ticket");
|
|
107
|
+ System.out.println("# " + "price" + " cents.");
|
|
108
|
+ System.out.println("##################");
|
|
109
|
+ System.out.println();
|
|
110
|
+
|
|
111
|
+ // Update the total collected with the balance.
|
|
112
|
+ total = total + balance;
|
|
113
|
+ // Clear the balance.
|
|
114
|
+ balance = 0;
|
|
115
|
+ }
|
|
116
|
+ }
|
|
117
|
+}
|