|
|
|
|
3
|
* **Objective** - to implement a `ZipCodeWilmington` _singleton_ which _mediates_ a _composite_ `Students` and `Instructors` reference.
|
3
|
* **Objective** - to implement a `ZipCodeWilmington` _singleton_ which _mediates_ a _composite_ `Students` and `Instructors` reference.
|
4
|
|
4
|
|
5
|
|
5
|
|
6
|
-# Part 1.1 - Create `Person` Class
|
|
|
|
|
6
|
+### Part 1.1 - Create `Person` Class
|
7
|
* Create a `Person` class.
|
7
|
* Create a `Person` class.
|
8
|
* The class should declare a `final` field named `id` of type `long`.
|
8
|
* The class should declare a `final` field named `id` of type `long`.
|
9
|
* `Person` constructor should have a parameter of type `long` which sets the `id` field to the respective value.
|
9
|
* `Person` constructor should have a parameter of type `long` which sets the `id` field to the respective value.
|
|
|
|
|
12
|
* The class should define a `setName()` method which sets the `Person` object's `name` field.
|
12
|
* The class should define a `setName()` method which sets the `Person` object's `name` field.
|
13
|
|
13
|
|
14
|
-
|
14
|
-
|
15
|
-# Part 1.0 - Test `Person`
|
|
|
|
|
15
|
+### Part 1.0 - Test `Person`
|
16
|
* Create a `TestPerson` class.
|
16
|
* Create a `TestPerson` class.
|
17
|
* Create a `testConstructor` method which ensures that a `Person` object's `id` field is being set upon construction.
|
17
|
* Create a `testConstructor` method which ensures that a `Person` object's `id` field is being set upon construction.
|
18
|
* Create a `testSetName` method which ensures that a `Person` object's `name` variable is being set by invoking the `.setName` method.
|
18
|
* Create a `testSetName` method which ensures that a `Person` object's `name` variable is being set by invoking the `.setName` method.
|
19
|
* Create a `testConstructor` method which ensures that a `Person` object's `name` variable is being set by invoking the `Person` constructor.
|
19
|
* Create a `testConstructor` method which ensures that a `Person` object's `name` variable is being set by invoking the `Person` constructor.
|
20
|
|
20
|
|
21
|
-
|
21
|
-
|
22
|
-# Part 2.0 - Create `Learner` Interface
|
|
|
|
|
22
|
+### Part 2.0 - Create `Learner` Interface
|
23
|
* Create a `Learner` interface.
|
23
|
* Create a `Learner` interface.
|
24
|
* `Learner` should declare one method signature:
|
24
|
* `Learner` should declare one method signature:
|
25
|
* Method name: `learn`
|
25
|
* Method name: `learn`
|
|
|
|
|
27
|
* Method return-type: `void`
|
27
|
* Method return-type: `void`
|
28
|
|
28
|
|
29
|
-
|
29
|
-
|
30
|
-# Part 3.1 - Create `Student` Class
|
|
|
|
|
30
|
+### Part 3.1 - Create `Student` Class
|
31
|
* Create a `Student` class such that:
|
31
|
* Create a `Student` class such that:
|
32
|
* `Student` is a subclass of `Person`
|
32
|
* `Student` is a subclass of `Person`
|
33
|
* `Student` implements the `Learner` interface
|
33
|
* `Student` implements the `Learner` interface
|
|
|
|
|
37
|
|
37
|
|
38
|
|
38
|
|
39
|
-
|
39
|
-
|
40
|
-# Part 3.0 - Test `Student`
|
|
|
|
|
40
|
+### Part 3.0 - Test `Student`
|
41
|
* Create a `TestStudent` class.
|
41
|
* Create a `TestStudent` class.
|
42
|
* Create a `testImplementation` method that asserts that a `Student` is an `instanceof` a `Learner`.
|
42
|
* Create a `testImplementation` method that asserts that a `Student` is an `instanceof` a `Learner`.
|
43
|
* Create a `testInheritance` method that asserts that a `Student` is an `instanceof` a `Person`.
|
43
|
* Create a `testInheritance` method that asserts that a `Student` is an `instanceof` a `Person`.
|
44
|
* Create a `testLearn` method that ensures a `Student`'s `totalStudyTime` instance variable is incremented by the specified `numberOfHours` by invoking the `.learn` method.
|
44
|
* Create a `testLearn` method that ensures a `Student`'s `totalStudyTime` instance variable is incremented by the specified `numberOfHours` by invoking the `.learn` method.
|
45
|
|
45
|
|
46
|
-
|
46
|
-
|
47
|
-# Part 4.0 - Create `Teacher` Interface
|
|
|
|
|
47
|
+### Part 4.0 - Create `Teacher` Interface
|
48
|
* Create a `Teacher` interface.
|
48
|
* Create a `Teacher` interface.
|
49
|
* `Teacher` should declare a `teach` method signature:
|
49
|
* `Teacher` should declare a `teach` method signature:
|
50
|
* Method name: `teach`
|
50
|
* Method name: `teach`
|
|
|
|
|
62
|
|
62
|
|
63
|
|
63
|
|
64
|
-
|
64
|
-
|
65
|
-# Part 5.1 - Create `Instructor` Class
|
|
|
|
|
65
|
+### Part 5.1 - Create `Instructor` Class
|
66
|
* Create an `Instructor` class such that:
|
66
|
* Create an `Instructor` class such that:
|
67
|
* `Instructor` is a subclass of `Person`
|
67
|
* `Instructor` is a subclass of `Person`
|
68
|
* `Instructor` implements the `Teacher` interface
|
68
|
* `Instructor` implements the `Teacher` interface
|
|
|
|
|
72
|
* `double numberOfHoursPerStudent = numberOfHours / students.length;`
|
72
|
* `double numberOfHoursPerStudent = numberOfHours / students.length;`
|
73
|
|
73
|
|
74
|
-
|
74
|
-
|
75
|
-# Part 5.0 - Test `Instructor`
|
|
|
|
|
75
|
+### Part 5.0 - Test `Instructor`
|
76
|
* Create a `TestInstructor` class.
|
76
|
* Create a `TestInstructor` class.
|
77
|
* Create a `testImplementation` method that asserts that an `Instructor` is an `instanceof` a `Teacher`.
|
77
|
* Create a `testImplementation` method that asserts that an `Instructor` is an `instanceof` a `Teacher`.
|
78
|
* Create a `testInheritance` method that asserts that a `Instructor` is an `instanceof` a `Person`.
|
78
|
* Create a `testInheritance` method that asserts that a `Instructor` is an `instanceof` a `Person`.
|
|
|
|
|
81
|
|
81
|
|
82
|
|
82
|
|
83
|
-
|
83
|
-
|
84
|
-# Part 6.1 - Create `People` class
|
|
|
|
|
84
|
+### Part 6.1 - Create `People` class
|
85
|
* Create a `People` class.
|
85
|
* Create a `People` class.
|
86
|
* The class should instantiate an `ArrayList` field of `Person` objects named `personList`.
|
86
|
* The class should instantiate an `ArrayList` field of `Person` objects named `personList`.
|
87
|
* The class should define a method named `add` which adds a `Person` to the `personList`.
|
87
|
* The class should define a method named `add` which adds a `Person` to the `personList`.
|
|
|
|
|
93
|
* The class should define a named `removeAll` which clears our `personList` field.
|
93
|
* The class should define a named `removeAll` which clears our `personList` field.
|
94
|
|
94
|
|
95
|
-
|
95
|
-
|
96
|
-# Part 6.0 - Test `People`
|
|
|
|
|
96
|
+### Part 6.0 - Test `People`
|
97
|
* Create a `TestPeople` class.
|
97
|
* Create a `TestPeople` class.
|
98
|
* Create a `testAdd` method which ensures that our `personList` in our `People` class populated with respective `Student` objects following invokation of the `addStudent` method.
|
98
|
* Create a `testAdd` method which ensures that our `personList` in our `People` class populated with respective `Student` objects following invokation of the `addStudent` method.
|
99
|
* Create a `testRemove` method which ensures that the `personList` in a `People` object is **depopulated** with a respective `Person` object following the invokation of the `remove` method.
|
99
|
* Create a `testRemove` method which ensures that the `personList` in a `People` object is **depopulated** with a respective `Person` object following the invokation of the `remove` method.
|
|
|
|
|
101
|
|
101
|
|
102
|
|
102
|
|
103
|
-
|
103
|
-
|
104
|
-# Part 7.1 - Create `Students` singleton
|
|
|
|
|
104
|
+### Part 7.1 - Create `Students` singleton
|
105
|
* **Note:** The creation of this class will demonstrate an implementation of [singleton design pattern](https://www.journaldev.com/1377/java-singleton-design-pattern-best-practices-examples#eager-initialization).
|
105
|
* **Note:** The creation of this class will demonstrate an implementation of [singleton design pattern](https://www.journaldev.com/1377/java-singleton-design-pattern-best-practices-examples#eager-initialization).
|
106
|
* Create a `Students` class.
|
106
|
* Create a `Students` class.
|
107
|
* The class should be an _unextendable_ subclass of the `People` class.
|
107
|
* The class should be an _unextendable_ subclass of the `People` class.
|
|
|
|
|
113
|
|
113
|
|
114
|
|
114
|
|
115
|
-
|
115
|
-
|
116
|
-# Part 7.0 - Test `Students` singleton
|
|
|
|
|
116
|
+### Part 7.0 - Test `Students` singleton
|
117
|
* Create a `TestStudents` class.
|
117
|
* Create a `TestStudents` class.
|
118
|
* Create a `test` method which ensures that each of the students in your current cohort are in your `Students` singleton.
|
118
|
* Create a `test` method which ensures that each of the students in your current cohort are in your `Students` singleton.
|
119
|
|
119
|
|
120
|
-
|
120
|
-
|
121
|
-# Part 7.2 - Create `Instructors` singleton
|
|
|
|
|
121
|
+### Part 7.2 - Create `Instructors` singleton
|
122
|
* Use `Part 7.0` and `Part 7.1` as a reference.
|
122
|
* Use `Part 7.0` and `Part 7.1` as a reference.
|
123
|
* Create a `Instructors` singleton which represents the set of instructors at ZipCodeWilmington.
|
123
|
* Create a `Instructors` singleton which represents the set of instructors at ZipCodeWilmington.
|
124
|
* Create a `TestInstructors` class.
|
124
|
* Create a `TestInstructors` class.
|
125
|
|
125
|
|
126
|
|
126
|
|
127
|
-# Part 8.1 - Create `ZipCodeWilmington` Class
|
|
|
|
|
127
|
+### Part 8.1 - Create `ZipCodeWilmington` Class
|
128
|
* Use `Part 7` as a reference.
|
128
|
* Use `Part 7` as a reference.
|
129
|
* Create a `ZipCodeWilmington` singleton.
|
129
|
* Create a `ZipCodeWilmington` singleton.
|
130
|
* The class should declare a field that references the instance of `Students` called `students`.
|
130
|
* The class should declare a field that references the instance of `Students` called `students`.
|
|
|
|
|
146
|
|
146
|
|
147
|
|
147
|
|
148
|
-
|
148
|
-
|
149
|
-# Notice the Design Flaw - Odd Casting Issues
|
|
|
|
|
149
|
+### Notice the Design Flaw - Odd Casting Issues
|
150
|
* You may have noticed that the `findById`, and `hostLecture` methods require an intermediate [casting trick](https://stackoverflow.com/questions/5289393/casting-variables-in-java).
|
150
|
* You may have noticed that the `findById`, and `hostLecture` methods require an intermediate [casting trick](https://stackoverflow.com/questions/5289393/casting-variables-in-java).
|
151
|
* To remedy this issue, we can _generify_ the `People` class.
|
151
|
* To remedy this issue, we can _generify_ the `People` class.
|
152
|
|
152
|
|
153
|
-# Part 9.1 - Modify `People` class
|
|
|
|
|
153
|
+### Part 9.1 - Modify `People` class
|
154
|
* [Parameterize](https://stackoverflow.com/questions/12551674/what-is-meant-by-parameterized-type) the `People` signature to enfore that it is a container for objects of type `E` such that `E` is a subclass of `Person`.
|
154
|
* [Parameterize](https://stackoverflow.com/questions/12551674/what-is-meant-by-parameterized-type) the `People` signature to enfore that it is a container for objects of type `E` such that `E` is a subclass of `Person`.
|
155
|
* Modify `people` field to enforce that is a container of objects of type `E`.
|
155
|
* Modify `people` field to enforce that is a container of objects of type `E`.
|
156
|
* Modify the `add` method to ensure that it handles object of type `E`.
|
156
|
* Modify the `add` method to ensure that it handles object of type `E`.
|
|
|
|
|
173
|
|
173
|
|
174
|
|
174
|
|
175
|
-
|
175
|
-
|
176
|
-# Notice the Design Flaw - Non-Intuitive Orientation
|
|
|
|
|
176
|
+### Notice the Design Flaw - Non-Intuitive Orientation
|
177
|
* You may have notice that `findById` makes it difficult to intuitively identify _which_ `Person` object is being returned.<br>
|
177
|
* You may have notice that `findById` makes it difficult to intuitively identify _which_ `Person` object is being returned.<br>
|
178
|
Additionally, it's challengaing to ensure **every** `Person` instance has a unique ID amongst its respective `People` subclass.<br>
|
178
|
Additionally, it's challengaing to ensure **every** `Person` instance has a unique ID amongst its respective `People` subclass.<br>
|
179
|
To remedy this issue, we redesign and refactor.
|
179
|
To remedy this issue, we redesign and refactor.
|
180
|
|
180
|
|
181
|
-# Part 9.1 - Create `Educator` enum
|
|
|
|
|
181
|
+### Part 9.1 - Create `Educator` enum
|
182
|
* Create an enum named `Educator`.
|
182
|
* Create an enum named `Educator`.
|
183
|
* The enum should implement `Teacher`.
|
183
|
* The enum should implement `Teacher`.
|
184
|
* The enum should have an enumeration for each of the instructors represented in the `Instructors` class.
|
184
|
* The enum should have an enumeration for each of the instructors represented in the `Instructors` class.
|
185
|
* The enum should have an _empty nullary constructor_.
|
185
|
* The enum should have an _empty nullary constructor_.
|
186
|
|
186
|
|
187
|
-# Part 9.0 - Test `Educator`
|
|
|
|
|
187
|
+### Part 9.0 - Test `Educator`
|
188
|
* Use `Part 5` as a reference.
|
188
|
* Use `Part 5` as a reference.
|
189
|
|
189
|
|
190
|
-# Part 10.1 - Modify `Instructor` Class
|
|
|
|
|
190
|
+### Part 10.1 - Modify `Instructor` Class
|
191
|
* Annotate the constructor with `@Deprecated`.
|
191
|
* Annotate the constructor with `@Deprecated`.
|
192
|
* This constructor should be commented with `//TODO - Remove dependencies`
|
192
|
* This constructor should be commented with `//TODO - Remove dependencies`
|
193
|
* Create a constructor in the `Instructor` class which uses `Educator educator` parameter to set a final `educator` field.
|
193
|
* Create a constructor in the `Instructor` class which uses `Educator educator` parameter to set a final `educator` field.
|
|
|
|
|
195
|
* Remove any calls being made to the deprecated construcor.
|
195
|
* Remove any calls being made to the deprecated construcor.
|
196
|
* Remove the deprecated constructor from the class.
|
196
|
* Remove the deprecated constructor from the class.
|
197
|
|
197
|
|
198
|
-# Part 10.0 - Test `Instructor`
|
|
|
|
|
198
|
+### Part 10.0 - Test `Instructor`
|
199
|
* Refactor `TestInstructor` to support the newly created `Instructor` constructor.
|
199
|
* Refactor `TestInstructor` to support the newly created `Instructor` constructor.
|
200
|
* Ensure the tests were not affected by the refactoring.
|
200
|
* Ensure the tests were not affected by the refactoring.
|