- Objective - to implement a
ZipCodeWilmingtonclass which mediates a compositeStudentsandInstructorssingleton reference. - Purpose - to demonstrate the use of
- Create a
Personclass.- The class should declare a
finalfield namedidof typelong. - The class should declare a field named
nameof typeString. Personconstructor should have a parameter of typelongandStringwhich sets theidandnamefield to the respective values.- The class should define a
getId()method which returns thePersonobject'sidfield. - The class should define a
getName()method which returns thePersonobject'snamefield. - The class should define a
setName()method which sets thePersonobject'snamefield.
- The class should declare a
- Create a
TestPersonclass.- Create a
testConstructormethod which ensures that aPersonobject'sidandnamefield are being set upon construction. - Create a
testSetNamemethod which ensures that aPersonobject'snamevariable is being set by invoking the.setNamemethod.
- Create a
- Create a
Learnerinterface.Learnershould declare method signature:- Method name:
learn - Method parameters:
double numberOfHours - Method return-type:
void
- Method name:
Learnershould declare method signature:- Method name:
getTotalStudyTime - Method return-type:
Double
- Method name:
- Create a
Studentclass such that:Studentis a subclass ofPersonStudentimplements theLearnerinterfaceStudentshould have an instance variabletotalStudyTimeof typedoubleStudentshould have a concrete implementation of thelearnmethod which increments thetotalStudyTimevariable by the specifiednumberOfHoursargument.Studentshould have agetTotalStudyTime()method which returns thetotalStudyTimeinstance variable.
- Create a
TestStudentclass.- Create a
testImplementationmethod that asserts that aStudentis aninstanceofaLearner. - Create a
testInheritancemethod that asserts that aStudentis aninstanceofaPerson. - Create a
testLearnmethod that ensures aStudent'stotalStudyTimeinstance variable is incremented by the specifiednumberOfHoursby invoking the.learnmethod.
- Create a
- Create a
Teacherinterface.-
Teachershould declare ateachmethod signature:- Method name:
teach - Method parameters:
Learner learnerdouble numberOfHours
- Method return-type:
void
- Method name:
-
Teachershould declare alecturemethod signature:- Method name:
lecture - Method parameters:
Learner[] learnersdouble numberOfHours
- Method return-type:
void
- Method name:
-
- Create an
Instructorclass such that:Instructoris a subclass ofPersonInstructorimplements theTeacherinterfaceInstructorshould have a concrete implementation of theteachmethod which invokes thelearnmethod on the specifiedLearnerobject.Instructorshould have a concrete implementation of thelecturemethod which invokes thelearnmethod on each of the elements in the specified array ofLearnerobjects.numberOfHoursshould be evenly split amongst the learners.double numberOfHoursPerLearner = numberOfHours / learners.length;
- Create a
TestInstructorclass.- Create a
testImplementationmethod that asserts that anInstructoris aninstanceofaTeacher. - Create a
testInheritancemethod that asserts that aInstructoris aninstanceofaPerson. - Create a
testTeachmethod that ensures when anInstructorinvokes theteachmethod, a respective student'stotalStudyTimeinstance variable is incremented by the specifiednumberOfHours. - Create a
testLecturemethod that ensures when anInstructorinvokes thelecturemethod, a respective array of students'totalStudyTimeinstance variables is incremented bynumberOfHours/students.length.
- Create a
- Create a
Peopleclass.- The class should instantiate a
Listfield ofPersonobjects namedpersonList. - The class should define a method named
addwhich adds aPersonto thepersonList. - The class should define a method named
findByIdwhich makes use of along idparameter to return aPersonobject with the respectiveidfield. - The class should define a named
containswhich makes use of aPerson personparameter to returntrueif thepersonListcontains the respectivePersonobject. - The class should define a method named
removewhich makes use of aPerson personparameter to remove a respectivePersonobject. - The class should define a method named
removewhich makes use of along idparameter to remove aPersonobject with the respectiveidfield. - The class should define a named
removeAllwhich clears ourpersonListfield. - The class should define a method named
countwhich returns the size ofpersonList. - The class should define a method named
toArraywhich returns an array representation of thepersonListfield. - The class should implement
Iterable<E>and define a method namediteratorwhich makes use of thepersonListfield to generate a new aIterator<E>.
- The class should instantiate a
- Create a
TestPeopleclass.- Create a
testAddmethod which ensures that ourpersonListin ourPeopleclass populated with respectivePersonobjects following invokation of theaddmethod. - Create a
testRemovemethod which ensures that thepersonListin aPeopleobject is depopulated with a respectivePersonobject following the invokation of theremovemethod. - Create a
testFindByIdmethod which ensures that a respectivePersonobject with a respectiveidfield is returned upon invokation of thefindByIdmethod on a respectivePeopleobject.
- Create a
- Note: The creation of this class will demonstrate an implementation of singleton design pattern.
- Create a
Studentsclass.- The class should be an unextendable subclass of the
Peopleclass. - The class should statically instantiate a
finalfield namedINSTANCEof typeStudents. - The class should define a private nullary constructor which populates the
INSTANCEfield with respectiveStudentrepresentations of your colleagues.- Each student should have a relatively unique
idfield.
- Each student should have a relatively unique
- The class should define a
getInstancemethod which returns theINSTANCEfield.
- The class should be an unextendable subclass of the
- Create a
TestStudentsclass.- Create a
testmethod which ensures that each of the students in your current cohort are in yourStudentssingleton.
- Create a
- Use
Part 7as a reference. - Create a
Instructorssingleton which represents the set of instructors at ZipCodeWilmington. - Create a
TestInstructorsclass.
- Create a
ZipCodeWilmingtonsingleton.- The class should declare a field that references the instance of
Studentscalledstudents. - The class should declare a field that references the instance of
Instructorscalledinstructors. - The class should define a method
hostLecturewhich makes use of aTeacher teacher, double numberOfHoursparameter to host alectureto the compositepersonListfield in thestudentsreference. - The class should define a method
hostLecturewhich makes use of along id, double numberOfHoursparameter to identify a respectiveInstructorto host alectureto the compositepersonListfield in thestudentsreference. - The class should define a method
getStudyMapwhich returns a new instance of a mapping fromStudentobjects toDoubleobjects, representative of each respective student'stotalStudyTime.
- The class should declare a field that references the instance of
- Create a
TestZipCodeWilmingtonclass.- Create a
testHostLecturemethod which ensures that each of theStudent'stotalStudyTimeinstance variable is incremented by the specifiednumberOfHoursupon invoking thehostLecturemethod.
- Create a
- You may have noticed that the
findById, andhostLecturemethods require an intermediate casting trick. - To remedy this issue, we can generify the
Peopleclass.
- Parameterize the
Peoplesignature to enforce that it is a container for objects of typeEsuch thatEis 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
peoplefield to enforce that is a container of objects of typeE. - Modify the
addmethod to ensure that it handles object of typeE. - Modify the
findByIdmethod to ensure that it returns an object of typeE. - Modify the
getArraymethod signature by declaring itabstractof return tyoeE.- An abstract method is a subclass's contractual agreement to the deferment of an implementation of a respective method.
- Modify the
Studentsclass signature to ensure that it is a subclass ofPeopleof parameterized typeStudent. - Modify the
Instructorsclass signature to ensure that it is a subclass ofPeopleof parameterized typeInstructor. - Provide concrete implementations of the
getArraymethod in each of these classes.
- Refactor the
hostLecturemethod in theZipCodeWilmingtonclass by removing any intermediate casting trick(s).
- Ensure that the
TestStudents,TestInstructors,TestPeople,TestZipCodeWilmingtonclasses were not affected by the refactor.
- You may have noticed that
findByIdmakes it difficult to intuitively identify whichPersonobject is being returned. To remedy this issue, we can make use of anenumwhich manipulates a compositeinstructorobject.
- Create an enum named
Educator.- The enum should implement
Teacher. - The enum should have an enumeration for each of the instructors represented in the
Instructorsclass. - Upon construction each enumeration of the enum should instantiate a respective
Instructorand assign it to a finalinstructorfield upon construction. Theinstructorshould be added to theInstructorssingleton. - Calls to the
teachandlecturemethod should be deferred to the compositeinstructorreference. - The enum should have a
double timeWorkedfield which keeps track of the hours that theEducatorhas taught.
- The enum should implement
- Use
Part 5as a reference.
- Ensure the
hostLecturemethod can handle objects of typeEducator.