浏览代码

changed description back to Leon's original description because are even more confused now

nhu313 6 年前
父节点
当前提交
974b7a0ab1
共有 1 个文件被更改,包括 107 次插入83 次删除
  1. 107
    83
      README.md

+ 107
- 83
README.md 查看文件

@@ -2,19 +2,23 @@
2 2
 * **Purpose** - to demonstrate the use of [Java interfaces](http://tutorials.jenkov.com/java/interfaces.html#java-interface-example)
3 3
 * **Objective** - to implement a `ZipCodeWilmington` class which _mediates_ a _composite_ `Students` and `Instructors` _singleton_ reference.
4 4
 
5
----
5
+
6
+### Part 1.1 - Create `Person` Class
7
+* Create a `Person` class.
8
+	* The class should declare a `final` field named `id` of type `long`.
9
+	* The class should declare a field named `name` of type `String`.	
10
+	* `Person` constructor should have a parameter of type `long` which sets the `id` field to the respective value.
11
+	* The class should define a `getId()` method which returns the `Person` object's `id` field.
12
+	* The class should define a `getName()` method which returns the `Person` object's `name` field.
13
+	* The class should define a `setName()` method which sets the `Person` object's `name` field.
14
+
15
+-
6 16
 ### Part 1.0 - Test `Person`
7
-* Create a `PersonTest` class.
8
-	* Create a `testConstructor` method which ensures that a `Person` object's `id` field is being set upon construction. To check if the id has been set, call the `getId()` method of the person class which will return a long
9
-        * Create a `Person` class.
10
-        * In the `Person` class, declare a `final` field named `id` of type `long`.
11
-        * Create a getter for the id field
12
-	* Create a `testSetAndGetName` method which ensures that a `Person` object's `name` variable is being set by invoking the `.setName` method and when you call `getName()` it will return the name you set
13
-        * In the `Person` class, declare a field named `name` of type `String`.
14
-        * The `Person` class should define a `getName()` method which returns the `Person` object's `name` field.
15
-        * The `Person` class should define a `setName()` method which sets the `Person` object's `name` field.
16
-
17
----
17
+* Create a `TestPerson` class.
18
+	* Create a `testConstructor` method which ensures that a `Person` object's `id` field is being set upon construction.
19
+	* Create a `testSetName` method which ensures that a `Person` object's `name` variable is being set by invoking the `.setName` method.
20
+
21
+-
18 22
 ### Part 2.0 - Create `Learner` Interface
19 23
 * Create a `Learner` interface.
20 24
 	* `Learner` should declare one method signature:
@@ -22,21 +26,24 @@
22 26
 		* Method parameters: `double numberOfHours`
23 27
 		* Method return-type: `void`
24 28
 
25
----
29
+-
30
+### Part 3.1 - Create `Student` Class
31
+* Create a `Student` class such that:
32
+	* `Student` is a subclass of `Person`
33
+	* `Student` implements the `Learner` interface
34
+	* `Student` should have an instance variable `totalStudyTime` of type `double`
35
+	* `Student` should have a concrete implementation of the `learn` method which increments the `totalStudyTime` variable by the specified `numberOfHours` argument.
36
+	* `Student` should have a `getTotalStudyTime()` method which returns the `totalStudyTime` instance variable.
37
+
38
+
39
+-
26 40
 ### Part 3.0 - Test `Student`
27
-* Create a `StudentTest` class.
41
+* Create a `TestStudent` class.
28 42
 	* Create a `testImplementation` method that asserts that a `Student` is an `instanceof` a `Learner`.
29
-        * Create a `Student` class
30
-        * `Student` implements the `Learner` interface
31
-        * Add a dummy implementation for the `learn` method
32 43
 	* Create a `testInheritance` method that asserts that a `Student` is an `instanceof` a `Person`.
33
-        * Make the `Student` class inherit from `Person`
34 44
 	* Create a `testLearn` method that ensures a `Student`'s `totalStudyTime` instance variable is incremented by the specified `numberOfHours` by invoking the `.learn` method.
35
-        * In the `Student` class, add a field called `totalStudyTime` of type `double`
36
-        * In the `Student` class, implementate the `learn` method which increments the `totalStudyTime` variable by the specified `numberOfHours` argument.`
37
-        * In the `Student` class, add a `getTotalStudyTime()` method which returns the `totalStudyTime` instance variable.
38 45
 
39
----
46
+-
40 47
 ### Part 4.0 - Create `Teacher` Interface
41 48
 * Create a `Teacher` interface.
42 49
 	* `Teacher` should declare a `teach` method signature:
@@ -53,78 +60,99 @@
53 60
 			* `double numberOfHours`
54 61
 		* Method return-type: `void`
55 62
 
56
----
63
+		
64
+-
65
+### Part 5.1 - Create `Instructor` Class
66
+* Create an `Instructor` class such that:
67
+	* `Instructor` is a subclass of `Person`
68
+	* `Instructor` implements the `Teacher` interface
69
+	* `Instructor` should have a concrete implementation of the `teach` method which invokes the `learn` method on the specified `Learner` object.
70
+	* `Instructor` should have a concrete implementation of the `lecture` method which invokes the `learn` method on each of the elements in the specified array of `Learner` objects.
71
+		* `numberOfHours` should be evenly split amongst the learners.
72
+			* `double numberOfHoursPerLearner = numberOfHours / learners.length;`
73
+
74
+-
57 75
 ### Part 5.0 - Test `Instructor`
58
-* Create a `InstructorTest` class.
76
+* Create a `TestInstructor` class.
59 77
 	* Create a `testImplementation` method that asserts that an `Instructor` is an `instanceof` a `Teacher`.
60
-        * Create an `Instructor` class such that:
61
-            * `Instructor` implements the `Teacher` interface
62
-            
63 78
 	* Create a `testInheritance` method that asserts that a `Instructor` is an `instanceof` a `Person`.
64
-        * Make the `Instructor` a subclass of `Person`
65 79
 	* Create a `testTeach` method that ensures when an `Instructor` invokes the `teach` method, a respective student's `totalStudyTime` instance variable is incremented by the specified `numberOfHours`.
66
-        * In the `Instructor` class, add a concrete implementation of the `teach` method which invokes the `learn` method on the specified `Learner` object.
67 80
 	* Create a `testLecture` method that ensures when an `Instructor` invokes the `lecture` method, a respective array of students' `totalStudyTime` instance variables is incremented by `numberOfHours/students.length`.
68
-        * `Instructor` should have a concrete implementation of the `lecture` method which invokes the `learn` method on each of the elements in the specified array of `Learner` objects.
69
-            * `numberOfHours` should be evenly split amongst the learners.
70
-                * `double numberOfHoursPerLearner = numberOfHours / learners.length;`
71 81
 
72
----
73
-### Part 6.0 - Test `People`
74
-* Create a `PeopleTest` class.
75
-* Create a `testAdd` method which ensures that our `personList` in our `People` class populated with respective `Person` objects following invokation of the `add` method.
76
-    * Create a `People` class.
77
-	* The `People` class should instantiate an `ArrayList` field of `Person` objects named `personList`.
78
-	* The `People` class should define a method named `add` which adds a `Person` to the `personList`.
79
-	* The `People` class should define a method named `getCount` which returns the size of `personList`.
80
-* Create a `testRemoveByPerson` method which ensures that the `personList` in a `People` object is **depopulated** with a respective `Person` object following the invokation of the `remove` method.
81
-    * The class should define a method named `remove` which makes use of a `Person person` parameter to remove a respective `Person` object.
82
-* Create a `testRemoveById` method which ensures that the `personList` in a `People` object is **depopulated** with a respective `Person` object following the invokation of the `remove` method.
82
+
83
+-
84
+### Part 6.1 - Create `People` class
85
+* Create a `People` class.
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`.
88
+	* The class should define a method named `findById` which makes use of a `long id` parameter to return a `Person` object with the respective `id` field.
89
+	* The class should define a method named `remove` which makes use of a `Person person` parameter to remove a respective `Person` object.
83 90
 	* The class should define a method named `remove` which makes use of a `long id` parameter to remove a `Person` object with the respective `id` field.
84
-* Create a `testFindById` method which ensures that a respective `Person` object with a respective `id` field is returned upon invokation of the `findById` method on a respective `People` object.
85
-    * The class should define a method named `findById` which makes use of a `long id` parameter to return a `Person` object with the respective `id` field.
86
-*  Create a `testGetArray` which ensures the array has all the people added
87
-    * In the `People` class, define a method named `getArray` which returns an array representation of the `personList` field.
88
-*  Create a `testRemoveAll` method which ensures you remove all the person added
89
-	* In the `People` class, define a method named `removeAll` which clears our `personList` field.
91
+	* The class should define a method named `getCount` which returns the size of `personList`.
92
+	* The class should define a method named `getArray` which returns an array representation of the `personList` field.
93
+	* The class should define a named `removeAll` which clears our `personList` field.
94
+	
95
+-
96
+### Part 6.0 - Test `People`
97
+* Create a `TestPeople` class.
98
+	* Create a `testAdd` method which ensures that our `personList` in our `People` class populated with respective `Person` objects following invokation of the `add` 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.
100
+	* Create a `testFindById` method which ensures that a respective `Person` object with a respective `id` field is returned upon invokation of the `findById` method on a respective `People` object.
90 101
 
91 102
 
92
----
103
+-
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).
106
+* Create a `Students` class.
107
+	* The class should be an _unextendable_ subclass of the `People` class.
108
+	* The class should _statically instantiate_ a `final` field named `INSTANCE` of type `Students`.
109
+	* The class should define a _private nullary constructor_ which populates the `INSTANCE` field with respective `Student` representations of your colleagues.
110
+		* Each student should have a _relatively_ unique `id` field.
111
+	* The class should define a `getInstance` method which returns the `INSTANCE` field.
112
+	
113
+	
114
+
115
+-
93 116
 ### Part 7.0 - Test `Students` singleton
94
-* **Note:** The creation of the `Students` will demonstrate an implementation of [singleton design pattern](https://www.journaldev.com/1377/java-singleton-design-pattern-best-practices-examples#eager-initialization).
95
-* Create a `StudentsTest` class.
96
-* Create a `testSingletonInstance` method which ensures that calling `Students.getInstance()` twice will return the same instance. You can check if they are the same instance by calling the `Assert.assertSame(instance1, instance2)` method.
97
-  * Create a `Students` class.
98
-  	* The class should be an _unextendable_ subclass of the `People` class.
99
-  	* The class should _statically instantiate_ a `final` field named `INSTANCE` of type `Students`.
100
-    * The class should define a _private nullary constructor_
101
-  	* The class should define a `getInstance` method which returns the `INSTANCE` field.
102
-* Create a `testInitializationSetupStudents` method which ensures that each of the students in your current cohort are in your `Students` singleton when `getArray` is called.
103
-  * In the constructor of the `Students` class, add all the students from your class so that calling `getArray` will return all the students from your cohort
104
-    * Each student should have a _relatively_ unique `id` field.
105
-
106
----
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.
119
+
120
+
121
+
122
+-
107 123
 ### Part 8.0 - Create and Test `Instructors` singleton
108 124
 * Use `Part 7` as a reference.
109
-* Create a `InstructorsTest` class.
110 125
 * Create a `Instructors` singleton which represents the set of instructors at ZipCodeWilmington.
126
+* Create a `TestInstructors` class.
127
+
111 128
 
112
----
113
-### Part 9.0 - `ZipCodeWilmington`
114
-* Create a `ZipCodeWilmingtonTest` class.
129
+-
130
+### Part 9.1 - Create `ZipCodeWilmington` Class
131
+* Create a `ZipCodeWilmington` singleton.
132
+	* The class should declare a field that references the instance of `Students` called `students`.
133
+	* The class should declare a field that references the instance of `Instructors` called `instructors`.
134
+	* The class should define a method `hostLecture` which makes use of a `Teacher teacher, double numberOfHours` parameter to host a `lecture` to the composite `people` field in the `students` reference.
135
+	* The class should define a method `hostLecture` which makes use of a `long id, double numberOfHours` parameter to identify a respective `Instructor` to host a `lecture` to the composite `people` field in the `cohort` reference.
136
+
137
+-
138
+### Part 9.0 - Test `ZipCodeWilmington`
139
+* Create a `TestZipCodeWilmington` class.
115 140
 	* Create a `testHostLecture` method which ensures that each of the `Student`'s `totalStudyTime` instance variable is incremented by the specified `numberOfHours` upon invoking the `hostLecture` method.
116
-    * Create a `ZipCodeWilmington` singleton.
117
-    	* The class should declare a field that references the instance of `Students` called `students`.
118
-    	* The class should declare a field that references the instance of `Instructors` called `instructors`.
119
-    	* The class should define a method `hostLecture` which makes use of a `Teacher teacher, double numberOfHours` parameter to host a `lecture` to the composite `people` field in the `students` reference.
120
-    	* The class should define a method `hostLecture` which makes use of a `long id, double numberOfHours` parameter to identify a respective `Instructor` to host a `lecture` to the composite `people` field in the `cohort` reference.
121 141
 
122
----
142
+
143
+
144
+
145
+
146
+
147
+
148
+
149
+
150
+-
123 151
 # Notice the Design Flaw - Odd Casting Issues
124 152
 * You may have noticed that the `findById`, and `hostLecture` methods require an intermediate [casting trick](https://stackoverflow.com/questions/5289393/casting-variables-in-java).
125 153
 * To remedy this issue, we can _generify_ the `People` class.
126 154
 
127
----
155
+-
128 156
 ### Part 10.1 - Modify `People` class
129 157
 * [Parameterize](https://stackoverflow.com/questions/12551674/what-is-meant-by-parameterized-type) the `People` signature to enforce that it is a container for objects of type `E` such that `E` is a subclass of `Person`.
130 158
 * Modify the class signature to declare this class _abstract_.
@@ -132,24 +160,22 @@
132 160
 * Modify `people` field to enforce that is a container of objects of type `E`.
133 161
 * Modify the `add` method to ensure that it handles object of type `E`.
134 162
 * Modify the `findById` method to ensure that it returns an object of type `E`.
135
-* Modify the `getArray` method signature by declaring it `abstract` of return type `E`.
163
+* Modify the `getArray` method signature by declaring it `abstract` of return tyoe `E`.
136 164
 	* An abstract method is a subclass's contractual agreement to the deferment of an implementation of a respective method.
137
-* You may need to create an [inner class](https://docs.oracle.com/javase/tutorial/java/javaOO/innerclasses.html) to test make the People class
138 165
 
139 166
 -
140 167
 ### Part 10.2 - Modify `People` subclasses
141 168
 * Modify the `Students` class signature to ensure that it is a subclass of `People` of parameterized type `Student`.
142 169
 * Modify the `Instructors` class signature to ensure that it is a subclass of `People` of parameterized type `Instructor`.
143
-* See if you can modify the `getArray` method in the `People` class to return the generic array back. Otherwise, add concrete implementations of the `getArray` method in each of these classes
144
-    * HINT: To create a new generic array, you can use `E[] array = (E[]) Array.newInstance(Student[].class.getComponentType(), list.size());`. Note in this code, when I call newInstance, I give the Student[].class. Change it so it can be Student[] or Instructor[] or Person[].
170
+* Provide concrete implementations of the `getArray` method in each of these classes.
145 171
 
146 172
 -
147 173
 ### Part 10.3 - Refactor `ZipCodeWilmington` class
148 174
 * Refactor the `hostLecture` method in the `ZipCodeWilmington` class by removing any intermediate _casting trick(s)_.
149 175
 
150 176
 -
151
-### Part 10.4 - Test refactored classes.
152
-* Ensure that the `StudentsTest`, `InstructorsTest`, `PeopleTest`, `ZipCodeWilmingtonTest` classes were not affected by the refactor.
177
+### Part 10.0 - Test refactored classes.
178
+* Ensure that the `TestStudents`, `TestInstructors`, `TestPeople`, `TestZipCodeWilmington` classes were not affected by the refactor.
153 179
 
154 180
 
155 181
 
@@ -165,11 +191,9 @@
165 191
 * Create an enum named `Educator`.
166 192
 	* The enum should implement `Teacher`.
167 193
 	* The enum should have an enumeration for each of the instructors represented in the `Instructors` class.
194
+	* Upon construction each enumeration of the enum should instantiate a respective `Instructor` and assign it to a final `instructor` field upon construction. The `instructor` should be added to the `Instructors` singleton.
168 195
 	* Calls to the `teach` and `lecture` method should be differed to the composite `instructor` reference.
169 196
 	* The enum should have a `double timeWorked` field which keeps track of the hours that the `Educator` has taught.
170
-* In the constuctor of the `Instructors` class, get all the `Educator` by calling `Educator.values()`, add all the instructor to   Upon construction each enumeration of the enum should instantiate a respective `Instructor` and assign it to a final `instructor` field upon construction. The `instructor` should be added to the `Instructors` singleton.
171
-
172
-
173 197
 
174 198
 -
175 199
 ### Part 11.0 - Test `Educator`