Selaa lähdekoodia

Read through Ch. 2 and completed series of exercises

Trinh Tong 6 vuotta sitten
vanhempi
commit
b33e2dfc37
3 muutettua tiedostoa jossa 49 lisäystä ja 22 poistoa
  1. 29
    2
      TicketMachine.java
  2. 10
    10
      bluej.pkg
  3. 10
    10
      package.bluej

+ 29
- 2
TicketMachine.java Näytä tiedosto

@@ -23,9 +23,16 @@ public class TicketMachine
23 23
      * Note that the price must be greater than zero, and there
24 24
      * are no checks to ensure this.
25 25
      */
26
-    public TicketMachine(int ticketCost)
26
+    public TicketMachine(int ticketPrice)
27 27
     {
28
-        price = ticketCost;
28
+        price = ticketPrice;
29
+        balance = 0;
30
+        total = 0;
31
+    }
32
+    
33
+    public TicketMachine()
34
+    {
35
+        price = 1000;
29 36
         balance = 0;
30 37
         total = 0;
31 38
     }
@@ -75,4 +82,24 @@ public class TicketMachine
75 82
         // Clear the balance.
76 83
         balance = 0;
77 84
     }
85
+    
86
+    public void prompt()
87
+    {
88
+        System.out.println("Please insert the correct amount of money.");
89
+    }    
90
+
91
+    public void showPrice()
92
+    {
93
+        System.out.println("The price of a ticket is " + price + " cents.");
94
+    }
95
+    
96
+    public void empty()
97
+    {
98
+        total = 0;
99
+    }
100
+    
101
+    public void changePrice(int newPrice)
102
+    {
103
+        price = newPrice;
104
+    }
78 105
 }

+ 10
- 10
bluej.pkg Näytä tiedosto

@@ -1,17 +1,17 @@
1 1
 #BlueJ package file
2 2
 editor.fx.0.height=722
3
-editor.fx.0.width=800
4
-editor.fx.0.x=709
5
-editor.fx.0.y=113
6
-objectbench.height=101
7
-objectbench.width=461
3
+editor.fx.0.width=625
4
+editor.fx.0.x=795
5
+editor.fx.0.y=40
6
+objectbench.height=175
7
+objectbench.width=776
8 8
 package.divider.horizontal=0.6
9
-package.divider.vertical=0.8007380073800738
10
-package.editor.height=427
9
+package.divider.vertical=0.7092651757188498
10
+package.editor.height=437
11 11
 package.editor.width=674
12
-package.editor.x=1067
13
-package.editor.y=119
14
-package.frame.height=600
12
+package.editor.x=624
13
+package.editor.y=201
14
+package.frame.height=684
15 15
 package.frame.width=800
16 16
 package.numDependencies=0
17 17
 package.numTargets=1

+ 10
- 10
package.bluej Näytä tiedosto

@@ -1,17 +1,17 @@
1 1
 #BlueJ package file
2 2
 editor.fx.0.height=722
3
-editor.fx.0.width=800
4
-editor.fx.0.x=709
5
-editor.fx.0.y=113
6
-objectbench.height=101
7
-objectbench.width=461
3
+editor.fx.0.width=625
4
+editor.fx.0.x=795
5
+editor.fx.0.y=40
6
+objectbench.height=175
7
+objectbench.width=776
8 8
 package.divider.horizontal=0.6
9
-package.divider.vertical=0.8007380073800738
10
-package.editor.height=427
9
+package.divider.vertical=0.7092651757188498
10
+package.editor.height=437
11 11
 package.editor.width=674
12
-package.editor.x=1067
13
-package.editor.y=119
14
-package.frame.height=600
12
+package.editor.x=624
13
+package.editor.y=201
14
+package.frame.height=684
15 15
 package.frame.width=800
16 16
 package.numDependencies=0
17 17
 package.numTargets=1