Tommy Rogers 6 lat temu
rodzic
commit
91e786d859
3 zmienionych plików z 91 dodań i 16 usunięć
  1. 79
    4
      TicketMachine.java
  2. 6
    6
      bluej.pkg
  3. 6
    6
      package.bluej

+ 79
- 4
TicketMachine.java Wyświetl plik

@@ -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,6 +17,10 @@ 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
+    //Exercise 2.15ls
21
+
22
+    private int status;
23
+    private int score;
20 24
 
21 25
     /**
22 26
      * Create a machine that issues tickets of the given price.
@@ -30,6 +34,33 @@ public class TicketMachine
30 34
         total = 0;
31 35
     }
32 36
 
37
+    public TicketMachine()
38
+    {
39
+        price = 10000;
40
+        balance = 0;
41
+        total = 0;
42
+    }
43
+
44
+    public void setPrice(/*int ticketCost*/){
45
+        price = 1000;//all tickets will begin with the state of 1000.
46
+    }
47
+
48
+    /**
49
+     * Remove all money from machine.
50
+     */
51
+    public void empty(/* none needed. */)//mutates the state of total.
52
+    {
53
+        total = 0;
54
+    }
55
+
56
+    /**
57
+     * Set the new price of a ticket.
58
+     */
59
+    public void setPrice2(int price2)//mutates the state of price.
60
+    {
61
+        price = price2;
62
+    }
63
+
33 64
     /**
34 65
      * Return the price of a ticket.
35 66
      */
@@ -37,22 +68,66 @@ public class TicketMachine
37 68
     {
38 69
         return price;
39 70
     }
40
-
71
+    //missing return statement
41 72
     /**
42 73
      * Return the amount of money already inserted for the
43 74
      * next ticket.
44 75
      */
45
-    public int getBalance()
76
+    public int getAmount()
46 77
     {
47 78
         return balance;
48 79
     }
49 80
 
50 81
     /**
82
+     * Return the total amount of money if additional money 
83
+     * is inserted to the balance.
84
+     */
85
+    public int getTotal()
86
+    {
87
+        return total;
88
+    }
89
+
90
+    /**
51 91
      * Receive an amount of money in cents from a customer.
52 92
      */
53 93
     public void insertMoney(int amount)
54 94
     {
55
-        balance = balance + amount;
95
+        balance += amount;
96
+    }
97
+
98
+    /**
99
+     * Increase score by the given number of points.
100
+     */
101
+    public void increase(int points)
102
+    {
103
+        score += points;
104
+    }
105
+
106
+    /**
107
+     * Reduce price by the given amount.
108
+     */
109
+    public void discount(int amount)
110
+    { 
111
+        price-= amount;
112
+    }
113
+
114
+    /**
115
+     * Print the message to insert the correct amount of money.
116
+     */
117
+    public void prompt()
118
+    { 
119
+        System.out.println("Please insert the correct amount of money.");
120
+    }//2.36 Print out line: # price cents.
121
+    //2.37 Prints the same at 2.36.
122
+    // Neither option has the price variable. They have a price string.  
123
+    // String does not represent price's state and cannot be mutated.
124
+
125
+    /**
126
+     * Print the price of the ticket.
127
+     */
128
+    public void showPrice()
129
+    { 
130
+        System.out.println("The price of a ticket is " + price + " cents.");
56 131
     }
57 132
 
58 133
     /**

+ 6
- 6
bluej.pkg Wyświetl plik

@@ -1,16 +1,16 @@
1 1
 #BlueJ package file
2
-editor.fx.0.height=722
2
+editor.fx.0.height=717
3 3
 editor.fx.0.width=800
4
-editor.fx.0.x=709
5
-editor.fx.0.y=113
4
+editor.fx.0.x=692
5
+editor.fx.0.y=31
6 6
 objectbench.height=101
7
-objectbench.width=461
7
+objectbench.width=776
8 8
 package.divider.horizontal=0.6
9 9
 package.divider.vertical=0.8007380073800738
10 10
 package.editor.height=427
11 11
 package.editor.width=674
12
-package.editor.x=1067
13
-package.editor.y=119
12
+package.editor.x=639
13
+package.editor.y=82
14 14
 package.frame.height=600
15 15
 package.frame.width=800
16 16
 package.numDependencies=0

+ 6
- 6
package.bluej Wyświetl plik

@@ -1,16 +1,16 @@
1 1
 #BlueJ package file
2
-editor.fx.0.height=722
2
+editor.fx.0.height=717
3 3
 editor.fx.0.width=800
4
-editor.fx.0.x=709
5
-editor.fx.0.y=113
4
+editor.fx.0.x=692
5
+editor.fx.0.y=31
6 6
 objectbench.height=101
7
-objectbench.width=461
7
+objectbench.width=776
8 8
 package.divider.horizontal=0.6
9 9
 package.divider.vertical=0.8007380073800738
10 10
 package.editor.height=427
11 11
 package.editor.width=674
12
-package.editor.x=1067
13
-package.editor.y=119
12
+package.editor.x=639
13
+package.editor.y=82
14 14
 package.frame.height=600
15 15
 package.frame.width=800
16 16
 package.numDependencies=0