Browse Source

COMPLETE#

shakila 6 years ago
parent
commit
557a79a0ed
6 changed files with 82 additions and 16 deletions
  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 View File


+ 2
- 0
README.TXT View File

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

+ 70
- 6
TicketMachine.java View File

8
  *
8
  *
9
  * @author David J. Barnes and Michael Kolling
9
  * @author David J. Barnes and Michael Kolling
10
  * @version 2008.03.30
10
  * @version 2008.03.30
11
- */
12
-public class TicketMachine
11
+ */ public class TicketMachine
13
 {
12
 {
14
     // The price of a ticket from this machine.
13
     // The price of a ticket from this machine.
15
-    private int price;
14
+    private int  price ;
16
     // The amount of money entered by a customer so far.
15
     // The amount of money entered by a customer so far.
17
     private int balance;
16
     private int balance;
18
     // The total amount of money collected by this machine.
17
     // The total amount of money collected by this machine.
19
     private int total;
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
      * Create a machine that issues tickets of the given price.
27
      * Create a machine that issues tickets of the given price.
23
      * Note that the price must be greater than zero, and there
28
      * Note that the price must be greater than zero, and there
24
      * are no checks to ensure this.
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
         balance = 0;
35
         balance = 0;
30
         total = 0;
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
      * Return the price of a ticket.
48
      * Return the price of a ticket.
38
         return price;
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
      * Return the amount of money already inserted for the
71
      * Return the amount of money already inserted for the
43
      * next ticket.
72
      * next ticket.
55
         balance = balance + amount;
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
      * Print a ticket.
96
      * Print a ticket.
60
      * Update the total collected and
97
      * Update the total collected and
75
         // Clear the balance.
112
         // Clear the balance.
76
         balance = 0;
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 View File

1
 #BlueJ package file
1
 #BlueJ package file
2
-editor.fx.0.height=722
2
+editor.fx.0.height=709
3
 editor.fx.0.width=800
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
 objectbench.height=101
6
 objectbench.height=101
7
 objectbench.width=461
7
 objectbench.width=461
8
 package.divider.horizontal=0.6
8
 package.divider.horizontal=0.6
9
 package.divider.vertical=0.8007380073800738
9
 package.divider.vertical=0.8007380073800738
10
 package.editor.height=427
10
 package.editor.height=427
11
 package.editor.width=674
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
 package.frame.height=600
14
 package.frame.height=600
15
 package.frame.width=800
15
 package.frame.width=800
16
 package.numDependencies=0
16
 package.numDependencies=0

BIN
doc/BlueJ-objects-first-ch2.pdf View File


+ 5
- 5
package.bluej View File

1
 #BlueJ package file
1
 #BlueJ package file
2
-editor.fx.0.height=722
2
+editor.fx.0.height=709
3
 editor.fx.0.width=800
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
 objectbench.height=101
6
 objectbench.height=101
7
 objectbench.width=461
7
 objectbench.width=461
8
 package.divider.horizontal=0.6
8
 package.divider.horizontal=0.6
9
 package.divider.vertical=0.8007380073800738
9
 package.divider.vertical=0.8007380073800738
10
 package.editor.height=427
10
 package.editor.height=427
11
 package.editor.width=674
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
 package.frame.height=600
14
 package.frame.height=600
15
 package.frame.width=800
15
 package.frame.width=800
16
 package.numDependencies=0
16
 package.numDependencies=0