- Objective - to implement a
ZipCodeWilmington
class which mediates a compositeStudents
andInstructors
singleton reference. - Purpose - to demonstrate the use of
- Create a
Person
class.- The class should declare a
final
field namedid
of typelong
. - The class should declare a field named
name
of typeString
. Person
constructor should have a parameter of typelong
andString
which sets theid
andname
field to the respective values.- The class should define a
getId()
method which returns thePerson
object'sid
field. - The class should define a
getName()
method which returns thePerson
object'sname
field. - The class should define a
setName()
method which sets thePerson
object'sname
field.
- The class should declare a
- Create a
TestPerson
class.- Create a
testConstructor
method which ensures that aPerson
object'sid
andname
field are being set upon construction. - Create a
testSetName
method which ensures that aPerson
object'sname
variable is being set by invoking the.setName
method.
- Create a
- Create a
Learner
interface.Learner
should declare method signature:- Method name:
learn
- Method parameters:
double numberOfHours
- Method return-type:
void
- Method name:
Learner
should declare method signature:- Method name:
getTotalStudyTime
- Method return-type:
Double
- Method name:
- Create a
Student
class such that:Student
is a subclass ofPerson
Student
implements theLearner
interfaceStudent
should have an instance variabletotalStudyTime
of typedouble
Student
should have a concrete implementation of thelearn
method which increments thetotalStudyTime
variable by the specifiednumberOfHours
argument.Student
should have agetTotalStudyTime()
method which returns thetotalStudyTime
instance variable.
- Create a
TestStudent
class.- Create a
testImplementation
method that asserts that aStudent
is aninstanceof
aLearner
. - Create a
testInheritance
method that asserts that aStudent
is aninstanceof
aPerson
. - Create a
testLearn
method that ensures aStudent
'stotalStudyTime
instance variable is incremented by the specifiednumberOfHours
by invoking the.learn
method.
- Create a
- Create a
Teacher
interface.-
Teacher
should declare ateach
method signature:- Method name:
teach
- Method parameters:
Learner learner
double numberOfHours
- Method return-type:
void
- Method name:
-
Teacher
should declare alecture
method signature:- Method name:
lecture
- Method parameters:
Learner[] learners
double numberOfHours
- Method return-type:
void
- Method name:
-
- Create an
Instructor
class such that:Instructor
is a subclass ofPerson
Instructor
implements theTeacher
interfaceInstructor
should have a concrete implementation of theteach
method which invokes thelearn
method on the specifiedLearner
object.Instructor
should have a concrete implementation of thelecture
method which invokes thelearn
method on each of the elements in the specified array ofLearner
objects.numberOfHours
should be evenly split amongst the learners.double numberOfHoursPerLearner = numberOfHours / learners.length;
- Create a
TestInstructor
class.- Create a
testImplementation
method that asserts that anInstructor
is aninstanceof
aTeacher
. - Create a
testInheritance
method that asserts that aInstructor
is aninstanceof
aPerson
. - Create a
testTeach
method that ensures when anInstructor
invokes theteach
method, a respective student'stotalStudyTime
instance variable is incremented by the specifiednumberOfHours
. - Create a
testLecture
method that ensures when anInstructor
invokes thelecture
method, a respective array of students'totalStudyTime
instance variables is incremented bynumberOfHours/students.length
.
- Create a
- Create a
People
class.- The class should instantiate a
List
field ofPerson
objects namedpersonList
. - The class should define a method named
add
which adds aPerson
to thepersonList
. - The class should define a method named
findById
which makes use of along id
parameter to return aPerson
object with the respectiveid
field. - The class should define a named
contains
which makes use of aPerson person
parameter to returntrue
if thepersonList
contains the respectivePerson
object. - The class should define a method named
remove
which makes use of aPerson person
parameter to remove a respectivePerson
object. - The class should define a method named
remove
which makes use of along id
parameter to remove aPerson
object with the respectiveid
field. - The class should define a named
removeAll
which clears ourpersonList
field. - The class should define a method named
count
which returns the size ofpersonList
. - The class should define a method named
toArray
which returns an array representation of thepersonList
field. - The class should implement
Iterable<E>
and define a method namediterator
which makes use of thepersonList
field to generate a new aIterator<E>
.
- The class should instantiate a
- Create a
TestPeople
class.- Create a
testAdd
method which ensures that ourpersonList
in ourPeople
class populated with respectivePerson
objects following invokation of theadd
method. - Create a
testRemove
method which ensures that thepersonList
in aPeople
object is depopulated with a respectivePerson
object following the invokation of theremove
method. - Create a
testFindById
method which ensures that a respectivePerson
object with a respectiveid
field is returned upon invokation of thefindById
method on a respectivePeople
object.
- Create a
- Note: The creation of this class will demonstrate an implementation of singleton design pattern.
- Create a
Students
class.- The class should be an unextendable subclass of the
People
class. - The class should statically instantiate a
final
field namedINSTANCE
of typeStudents
. - The class should define a private nullary constructor which populates the
INSTANCE
field with respectiveStudent
representations of your colleagues.- Each student should have a relatively unique
id
field.
- Each student should have a relatively unique
- The class should define a
getInstance
method which returns theINSTANCE
field.
- The class should be an unextendable subclass of the
- Create a
TestStudents
class.- Create a
test
method which ensures that each of the students in your current cohort are in yourStudents
singleton.
- Create a
- Use
Part 7
as a reference. - Create a
Instructors
singleton which represents the set of instructors at ZipCodeWilmington. - Create a
TestInstructors
class.
- Create a
ZipCodeWilmington
singleton.- The class should declare a field that references the instance of
Students
calledstudents
. - The class should declare a field that references the instance of
Instructors
calledinstructors
. - The class should define a method
hostLecture
which makes use of aTeacher teacher, double numberOfHours
parameter to host alecture
to the compositepersonList
field in thestudents
reference. - The class should define a method
hostLecture
which makes use of along id, double numberOfHours
parameter to identify a respectiveInstructor
to host alecture
to the compositepersonList
field in thestudents
reference. - The class should define a method
getStudyMap
which returns a new instance of a mapping fromStudent
objects toDouble
objects, representative of each respective student'stotalStudyTime
.
- The class should declare a field that references the instance of
- Create a
TestZipCodeWilmington
class.- Create a
testHostLecture
method which ensures that each of theStudent
'stotalStudyTime
instance variable is incremented by the specifiednumberOfHours
upon invoking thehostLecture
method.
- Create a
- You may have noticed that the
findById
, andhostLecture
methods require an intermediate casting trick. - To remedy this issue, we can generify the
People
class.
- Parameterize the
People
signature to enforce that it is a container for objects of typeE
such thatE
is a subclass ofPerson
. - Modify the class signature to declare this class abstract.
- An abstract class cannot be instantiated; Its concrete implementation is deferred to its subclass.
- Modify
people
field to enforce that is a container of objects of typeE
. - Modify the
add
method to ensure that it handles object of typeE
. - Modify the
findById
method to ensure that it returns an object of typeE
. - Modify the
getArray
method signature by declaring itabstract
of return tyoeE
.- An abstract method is a subclass's contractual agreement to the deferment of an implementation of a respective method.
- Modify the
Students
class signature to ensure that it is a subclass ofPeople
of parameterized typeStudent
. - Modify the
Instructors
class signature to ensure that it is a subclass ofPeople
of parameterized typeInstructor
. - Provide concrete implementations of the
getArray
method in each of these classes.
- Refactor the
hostLecture
method in theZipCodeWilmington
class by removing any intermediate casting trick(s).
- Ensure that the
TestStudents
,TestInstructors
,TestPeople
,TestZipCodeWilmington
classes were not affected by the refactor.
- You may have noticed that
findById
makes it difficult to intuitively identify whichPerson
object is being returned. To remedy this issue, we can make use of anenum
which manipulates a compositeinstructor
object.
- Create an enum named
Educator
.- The enum should implement
Teacher
. - The enum should have an enumeration for each of the instructors represented in the
Instructors
class. - Upon construction each enumeration of the enum should instantiate a respective
Instructor
and assign it to a finalinstructor
field upon construction. Theinstructor
should be added to theInstructors
singleton. - Calls to the
teach
andlecture
method should be deferred to the compositeinstructor
reference. - The enum should have a
double timeWorked
field which keeps track of the hours that theEducator
has taught.
- The enum should implement
- Use
Part 5
as a reference.
- Ensure the
hostLecture
method can handle objects of typeEducator
.