|
|
|
|
8
|
Work through all these exercises. You edit this file with your answers for these exercises.
|
8
|
Work through all these exercises. You edit this file with your answers for these exercises.
|
9
|
|
9
|
|
10
|
### Exercise 2.1
|
10
|
### Exercise 2.1
|
11
|
-* Create a `TicketMachine` object on the object bench.
|
|
|
12
|
-* The following methods should be available upon invoking it from the object bench `getBalance`, `getPrice`, `insertMoney`, `printTicket`.
|
|
|
|
|
11
|
+* Create a TicketMachine object on the object bench.
|
|
|
12
|
+* Upon viewing its methods, `getBalance`, `getPrice`, `insertMoney`, `printTicket`.
|
13
|
* Use `getPrice` method to view the value of the price of the tickets that was set when this object was created.
|
13
|
* Use `getPrice` method to view the value of the price of the tickets that was set when this object was created.
|
14
|
* Use `insertMoney` method to simulate inserting an amount of money into the machine.
|
14
|
* Use `insertMoney` method to simulate inserting an amount of money into the machine.
|
15
|
* Use `getBalance` to check that the machine has a record of the amount inserted.
|
15
|
* Use `getBalance` to check that the machine has a record of the amount inserted.
|
|
|
|
|
60
|
|
60
|
|
61
|
### Exercise 2.11
|
61
|
### Exercise 2.11
|
62
|
* What do you think is the type of each of the following fields?
|
62
|
* What do you think is the type of each of the following fields?
|
63
|
-```
|
|
|
|
|
63
|
+
|
|
|
64
|
+```java
|
64
|
private int count;
|
65
|
private int count;
|
65
|
private Student representative;
|
66
|
private Student representative;
|
66
|
private Server host;
|
67
|
private Server host;
|
|
|
|
|
68
|
|
69
|
|
69
|
### Exercise 2.12
|
70
|
### Exercise 2.12
|
70
|
* What are the names of the following fields?
|
71
|
* What are the names of the following fields?
|
71
|
-```
|
|
|
|
|
72
|
+
|
|
|
73
|
+```java
|
72
|
private boolean alive;
|
74
|
private boolean alive;
|
73
|
private Person tutor;
|
75
|
private Person tutor;
|
74
|
private Game game;
|
76
|
private Game game;
|
|
|
|
|
76
|
### Exercise 2.13
|
78
|
### Exercise 2.13
|
77
|
|
79
|
|
78
|
In the following field declaration from the TicketMachine class<br>
|
80
|
In the following field declaration from the TicketMachine class<br>
|
79
|
-```
|
|
|
|
|
81
|
+
|
|
|
82
|
+```java
|
80
|
private int price;
|
83
|
private int price;
|
81
|
-```<br>
|
|
|
|
|
84
|
+```
|
82
|
does it matter which order the three words appear in?
|
85
|
does it matter which order the three words appear in?
|
83
|
-
|
|
|
84
|
* Edit the `TicketMachine` class to try different orderings. After each change, close the editor.
|
86
|
* Edit the `TicketMachine` class to try different orderings. After each change, close the editor.
|
85
|
* Does the appearance of the class diagram after each change give you a clue as to whether or not other orderings are
|
87
|
* Does the appearance of the class diagram after each change give you a clue as to whether or not other orderings are
|
86
|
possible?
|
88
|
possible?
|