Parcourir la source

Update 'README.md'

nhu313 il y a 6 ans
Parent
révision
132cce931b
1 fichiers modifiés avec 84 ajouts et 110 suppressions
  1. 84
    110
      README.md

+ 84
- 110
README.md Voir le fichier

@@ -2,23 +2,19 @@
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
-
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
--
5
+---
16 6
 ### Part 1.0 - Test `Person`
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
--
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
+---
22 18
 ### Part 2.0 - Create `Learner` Interface
23 19
 * Create a `Learner` interface.
24 20
 	* `Learner` should declare one method signature:
@@ -26,24 +22,21 @@
26 22
 		* Method parameters: `double numberOfHours`
27 23
 		* Method return-type: `void`
28 24
 
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
--
25
+---
40 26
 ### Part 3.0 - Test `Student`
41
-* Create a `TestStudent` class.
27
+* Create a `StudentTest` class.
42 28
 	* 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
43 32
 	* Create a `testInheritance` method that asserts that a `Student` is an `instanceof` a `Person`.
33
+        * Make the `Student` class inherit from `Person`
44 34
 	* 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.
45 38
 
46
--
39
+---
47 40
 ### Part 4.0 - Create `Teacher` Interface
48 41
 * Create a `Teacher` interface.
49 42
 	* `Teacher` should declare a `teach` method signature:
@@ -60,99 +53,78 @@
60 53
 			* `double numberOfHours`
61 54
 		* Method return-type: `void`
62 55
 
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
--
56
+---
75 57
 ### Part 5.0 - Test `Instructor`
76
-* Create a `TestInstructor` class.
58
+* Create a `InstructorTest` class.
77 59
 	* 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
+            
78 63
 	* Create a `testInheritance` method that asserts that a `Instructor` is an `instanceof` a `Person`.
64
+        * Make the `Instructor` a subclass of `Person`
79 65
 	* 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.
80 67
 	* 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;`
81 71
 
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.
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.
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
--
72
+---
96 73
 ### 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.
101
-
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.
83
+	* 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.
102 90
 
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 91
 
115
--
92
+---
116 93
 ### Part 7.0 - Test `Students` singleton
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
--
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
+---
123 107
 ### Part 8.0 - Create and Test `Instructors` singleton
124 108
 * Use `Part 7` as a reference.
109
+* Create a `InstructorsTest` class.
125 110
 * Create a `Instructors` singleton which represents the set of instructors at ZipCodeWilmington.
126
-* Create a `TestInstructors` class.
127
-
128
-
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 111
 
137
--
138
-### Part 9.0 - Test `ZipCodeWilmington`
139
-* Create a `TestZipCodeWilmington` class.
112
+---
113
+### Part 9.0 - `ZipCodeWilmington`
114
+* Create a `ZipCodeWilmingtonTest` class.
140 115
 	* 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.
141 121
 
142
-
143
-
144
-
145
-
146
-
147
-
148
-
149
-
150
--
122
+---
151 123
 # Notice the Design Flaw - Odd Casting Issues
152 124
 * You may have noticed that the `findById`, and `hostLecture` methods require an intermediate [casting trick](https://stackoverflow.com/questions/5289393/casting-variables-in-java).
153 125
 * To remedy this issue, we can _generify_ the `People` class.
154 126
 
155
--
127
+---
156 128
 ### Part 10.1 - Modify `People` class
157 129
 * [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`.
158 130
 * Modify the class signature to declare this class _abstract_.
@@ -160,22 +132,22 @@
160 132
 * Modify `people` field to enforce that is a container of objects of type `E`.
161 133
 * Modify the `add` method to ensure that it handles object of type `E`.
162 134
 * Modify the `findById` method to ensure that it returns an object of type `E`.
163
-* Modify the `getArray` method signature by declaring it `abstract` of return tyoe `E`.
135
+* Modify the `getArray` method signature by declaring it `abstract` of return type `E`.
164 136
 	* An abstract method is a subclass's contractual agreement to the deferment of an implementation of a respective method.
165
-
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
166 138
 -
167 139
 ### Part 10.2 - Modify `People` subclasses
168 140
 * Modify the `Students` class signature to ensure that it is a subclass of `People` of parameterized type `Student`.
169 141
 * Modify the `Instructors` class signature to ensure that it is a subclass of `People` of parameterized type `Instructor`.
170
-* Provide concrete implementations of the `getArray` method in each of these classes.
171
-
142
+* 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
143
+  * 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[].
172 144
 -
173 145
 ### Part 10.3 - Refactor `ZipCodeWilmington` class
174 146
 * Refactor the `hostLecture` method in the `ZipCodeWilmington` class by removing any intermediate _casting trick(s)_.
175 147
 
176 148
 -
177
-### Part 10.0 - Test refactored classes.
178
-* Ensure that the `TestStudents`, `TestInstructors`, `TestPeople`, `TestZipCodeWilmington` classes were not affected by the refactor.
149
+### Part 10.4 - Test refactored classes.
150
+* Ensure that the `StudentsTest`, `InstructorsTest`, `PeopleTest`, `ZipCodeWilmingtonTest` classes were not affected by the refactor.
179 151
 
180 152
 
181 153
 
@@ -191,9 +163,11 @@
191 163
 * Create an enum named `Educator`.
192 164
 	* The enum should implement `Teacher`.
193 165
 	* 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.
195 166
 	* Calls to the `teach` and `lecture` method should be differed to the composite `instructor` reference.
196 167
 	* The enum should have a `double timeWorked` field which keeps track of the hours that the `Educator` has taught.
168
+* 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.
169
+
170
+
197 171
 
198 172
 -
199 173
 ### Part 11.0 - Test `Educator`
@@ -202,4 +176,4 @@
202 176
 
203 177
 -
204 178
 ### Part 12.0 - Test `ZipCodeWilmington`
205
-* Ensure the `hostLecture` method can handle objects of type `Educator`.
179
+* Ensure the `hostLecture` method can handle objects of type `Educator`.