Ahmad Rusdi 6 yıl önce
ebeveyn
işleme
593146406b
4 değiştirilmiş dosya ile 61 ekleme ve 23 silme
  1. 41
    3
      TicketMachine.java
  2. 10
    10
      bluej.pkg
  3. BIN
      doc/BlueJ-objects-first-ch2.pdf
  4. 10
    10
      package.bluej

+ 41
- 3
TicketMachine.java Dosyayı Görüntüle

@@ -17,18 +17,27 @@ 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
-
20
+    // Excersise 2.15.
21
+    private int status;
22
+    
23
+    public TicketMachine(int amount) {
24
+        price = amount;
25
+        balance = 0;
26
+        total = 0;
27
+    }
28
+    
21 29
     /**
22 30
      * Create a machine that issues tickets of the given price.
23 31
      * Note that the price must be greater than zero, and there
24 32
      * are no checks to ensure this.
25 33
      */
26
-    public TicketMachine(int ticketCost)
34
+    public TicketMachine()
27 35
     {
28
-        price = ticketCost;
36
+        price = 1000;
29 37
         balance = 0;
30 38
         total = 0;
31 39
     }
40
+    
32 41
 
33 42
     /**
34 43
      * Return the price of a ticket.
@@ -46,6 +55,17 @@ public class TicketMachine
46 55
     {
47 56
         return balance;
48 57
     }
58
+    
59
+    // Excercise 2.24
60
+    public int getTotal()
61
+    {
62
+        return total;
63
+    }
64
+    
65
+    // Excercise 2.30 + 2.41
66
+    public void setPrice(int amount) {
67
+        price = amount;
68
+    }
49 69
 
50 70
     /**
51 71
      * Receive an amount of money in cents from a customer.
@@ -55,6 +75,18 @@ public class TicketMachine
55 75
         balance = balance + amount;
56 76
     }
57 77
 
78
+    // Excercise 2.33
79
+    public void prompt()
80
+    {
81
+        System.out.println("Please insert the correct amount of money.");
82
+    }
83
+    
84
+    // Excercise 2.34
85
+    public void showPrice()
86
+    {
87
+        System.out.println("The price of a ticket is " + price + " cents.");
88
+    }
89
+    
58 90
     /**
59 91
      * Print a ticket.
60 92
      * Update the total collected and
@@ -75,4 +107,10 @@ public class TicketMachine
75 107
         // Clear the balance.
76 108
         balance = 0;
77 109
     }
110
+    
111
+    // Excercise 2.40
112
+    public void empty()
113
+    {
114
+        total = 0;
115
+    }
78 116
 }

+ 10
- 10
bluej.pkg Dosyayı Görüntüle

@@ -1,16 +1,16 @@
1 1
 #BlueJ package file
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
2
+editor.fx.0.height=777
3
+editor.fx.0.width=640
4
+editor.fx.0.x=640
5
+editor.fx.0.y=23
6
+objectbench.height=164
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.6845018450184502
10
+package.editor.height=364
11 11
 package.editor.width=674
12
-package.editor.x=1067
13
-package.editor.y=119
12
+package.editor.x=576
13
+package.editor.y=89
14 14
 package.frame.height=600
15 15
 package.frame.width=800
16 16
 package.numDependencies=0

BIN
doc/BlueJ-objects-first-ch2.pdf Dosyayı Görüntüle


+ 10
- 10
package.bluej Dosyayı Görüntüle

@@ -1,16 +1,16 @@
1 1
 #BlueJ package file
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
2
+editor.fx.0.height=777
3
+editor.fx.0.width=640
4
+editor.fx.0.x=640
5
+editor.fx.0.y=23
6
+objectbench.height=164
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.6845018450184502
10
+package.editor.height=364
11 11
 package.editor.width=674
12
-package.editor.x=1067
13
-package.editor.y=119
12
+package.editor.x=576
13
+package.editor.y=89
14 14
 package.frame.height=600
15 15
 package.frame.width=800
16 16
 package.numDependencies=0