shakila 6 anos atrás
pai
commit
557a79a0ed
6 arquivos alterados com 82 adições e 16 exclusões
  1. BIN
      .DS_Store
  2. 2
    0
      README.TXT
  3. 70
    6
      TicketMachine.java
  4. 5
    5
      bluej.pkg
  5. BIN
      doc/BlueJ-objects-first-ch2.pdf
  6. 5
    5
      package.bluej

BIN
.DS_Store Ver arquivo


+ 2
- 0
README.TXT Ver arquivo

@@ -1,3 +1,5 @@
1
+Shakila M. - Completed exercises until page 31. No access to project 'better-ticket-machine'.
2
+
1 3
 Project: naive-ticket-machine
2 4
 Authors: David Barnes and Michael Kolling
3 5
 

+ 70
- 6
TicketMachine.java Ver arquivo

@@ -8,27 +8,41 @@
8 8
  *
9 9
  * @author David J. Barnes and Michael Kolling
10 10
  * @version 2008.03.30
11
- */
12
-public class TicketMachine
11
+ */ public class TicketMachine
13 12
 {
14 13
     // The price of a ticket from this machine.
15
-    private int price;
14
+    private int  price ;
16 15
     // The amount of money entered by a customer so far.
17 16
     private int balance;
18 17
     // The total amount of money collected by this machine.
19 18
     private int total;
19
+    /**
20
+     * Exercise 2.15 Write in full the 
21
+     * declaration for a field of type 
22
+     * int whose name is status.
23
+     */
24
+    private int status;
20 25
 
21 26
     /**
22 27
      * Create a machine that issues tickets of the given price.
23 28
      * Note that the price must be greater than zero, and there
24 29
      * are no checks to ensure this.
30
+     * Exercise 2.39
25 31
      */
26
-    public TicketMachine(int ticketCost)
32
+    public TicketMachine()
27 33
     {
28
-        price = ticketCost;
34
+        price = 1000;
29 35
         balance = 0;
30 36
         total = 0;
31 37
     }
38
+    
39
+    /**Exercise 2.42
40
+     * 
41
+     */
42
+    public void TicketSet(int ticketCost)
43
+    {
44
+        price = ticketCost;
45
+    }
32 46
 
33 47
     /**
34 48
      * Return the price of a ticket.
@@ -38,6 +52,21 @@ public class TicketMachine
38 52
         return price;
39 53
     }
40 54
 
55
+    /**Exercise 2.33
56
+     * Request the correct amount of money
57
+     */
58
+    public void prompt()
59
+    {
60
+        System.out.println("Please insert the correct amount of money.");
61
+    }
62
+    
63
+    /**Exercise 2.34
64
+     * Show price
65
+     */
66
+    public void showPrice()
67
+    {
68
+        System.out.println("The price of the ticket is " + price);
69
+    }
41 70
     /**
42 71
      * Return the amount of money already inserted for the
43 72
      * next ticket.
@@ -55,6 +84,14 @@ public class TicketMachine
55 84
         balance = balance + amount;
56 85
     }
57 86
 
87
+    /**Exercise 2.24 Define an accessor method, getTotal, 
88
+     * that returns the value of the total field.
89
+     */
90
+    public int getTotal()
91
+    {
92
+        return total;
93
+    }
94
+
58 95
     /**
59 96
      * Print a ticket.
60 97
      * Update the total collected and
@@ -75,4 +112,31 @@ public class TicketMachine
75 112
         // Clear the balance.
76 113
         balance = 0;
77 114
     }
78
-}
115
+
116
+    /**
117
+     * Exercise 2.30 & 2.41
118
+     * Set Price
119
+     */
120
+    public void setPrice(int newValue)
121
+    {
122
+        price = newValue;
123
+        //return price;
124
+    }    
125
+
126
+    /**
127
+     * Exercise 2.32
128
+     * Reduce price by the given amount.
129
+     */
130
+    public void discount(int amount)
131
+    {
132
+      price = price - amount;  
133
+         }
134
+
135
+    /**Exercise 2.40
136
+     * Empty machine
137
+     */    
138
+    public void empty()
139
+    {
140
+        total = 0;
141
+    }
142
+        }

+ 5
- 5
bluej.pkg Ver arquivo

@@ -1,16 +1,16 @@
1 1
 #BlueJ package file
2
-editor.fx.0.height=722
2
+editor.fx.0.height=709
3 3
 editor.fx.0.width=800
4
-editor.fx.0.x=709
5
-editor.fx.0.y=113
4
+editor.fx.0.x=184
5
+editor.fx.0.y=23
6 6
 objectbench.height=101
7 7
 objectbench.width=461
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=157
13
+package.editor.y=73
14 14
 package.frame.height=600
15 15
 package.frame.width=800
16 16
 package.numDependencies=0

BIN
doc/BlueJ-objects-first-ch2.pdf Ver arquivo


+ 5
- 5
package.bluej Ver arquivo

@@ -1,16 +1,16 @@
1 1
 #BlueJ package file
2
-editor.fx.0.height=722
2
+editor.fx.0.height=709
3 3
 editor.fx.0.width=800
4
-editor.fx.0.x=709
5
-editor.fx.0.y=113
4
+editor.fx.0.x=184
5
+editor.fx.0.y=23
6 6
 objectbench.height=101
7 7
 objectbench.width=461
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=157
13
+package.editor.y=73
14 14
 package.frame.height=600
15 15
 package.frame.width=800
16 16
 package.numDependencies=0