Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Week 4 Project: Instructor, Student, Classroom

NotificationsYou must be signed in to change notification settings

ZipCodeCore/Maven.LearnerLab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Part 1.1 - CreatePerson Class

  • Create aPerson class.
    • The class should declare afinal field namedid of typelong.
    • The class should declare a field namedname of typeString.
    • Person constructor should have a parameter of typelong andString which sets theid andname field to the respective values.
    • The class should define agetId() method which returns thePerson object'sid field.
    • The class should define agetName() method which returns thePerson object'sname field.
    • The class should define asetName() method which sets thePerson object'sname field.

Part 1.0 - TestPerson

  • Create aTestPerson class.
    • Create atestConstructor method which ensures that aPerson object'sid andname field are being set upon construction.
    • Create atestSetName method which ensures that aPerson object'sname variable is being set by invoking the.setName method.

Part 2.0 - CreateLearner Interface

  • Create aLearner interface.
    • Learner should declare method signature:
      • Method name:learn
      • Method parameters:double numberOfHours
      • Method return-type:void
    • Learner should declare method signature:
      • Method name:getTotalStudyTime
      • Method return-type:Double

Part 3.1 - CreateStudent Class

  • Create aStudent class such that:
    • Student is a subclass ofPerson
    • Student implements theLearner interface
    • Student 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.

Part 3.0 - TestStudent

  • Create aTestStudent class.
    • Create atestImplementation method that asserts that aStudent is aninstanceof aLearner.
    • Create atestInheritance method that asserts that aStudent is aninstanceof aPerson.
    • Create atestLearn method that ensures aStudent'stotalStudyTime instance variable is incremented by the specifiednumberOfHours by invoking the.learn method.

Part 4.0 - CreateTeacher Interface

  • Create aTeacher interface.
    • Teacher should declare ateach method signature:

      • Method name:teach
      • Method parameters:
        • Learner learner
        • double numberOfHours
      • Method return-type:void
    • Teacher should declare alecture method signature:

      • Method name:lecture
      • Method parameters:
        • Learner[] learners
        • double numberOfHours
      • Method return-type:void

Part 5.1 - CreateInstructor Class

  • Create anInstructor class such that:
    • Instructor is a subclass ofPerson
    • Instructor implements theTeacher interface
    • Instructor 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;

Part 5.0 - TestInstructor

  • Create aTestInstructor class.
    • Create atestImplementation method that asserts that anInstructor is aninstanceof aTeacher.
    • Create atestInheritance method that asserts that aInstructor is aninstanceof aPerson.
    • Create atestTeach method that ensures when anInstructor invokes theteach method, a respective student'stotalStudyTime instance variable is incremented by the specifiednumberOfHours.
    • Create atestLecture method that ensures when anInstructor invokes thelecture method, a respective array of students'totalStudyTime instance variables is incremented bynumberOfHours/students.length.

Part 6.1 - CreatePeople class

  • Create aPeople class.
    • The class should instantiate aList field ofPerson objects namedpersonList.
    • The class should define a method namedadd which adds aPerson to thepersonList.
    • The class should define a method namedfindById which makes use of along id parameter to return aPerson object with the respectiveid field.
    • The class should define a namedcontains which makes use of aPerson person parameter to returntrue if thepersonList contains the respectivePerson object.
    • The class should define a method namedremove which makes use of aPerson person parameter to remove a respectivePerson object.
    • The class should define a method namedremove which makes use of along id parameter to remove aPerson object with the respectiveid field.
    • The class should define a namedremoveAll which clears ourpersonList field.
    • The class should define a method namedcount which returns the size ofpersonList.
    • The class should define a method namedtoArray which returns an array representation of thepersonList field.
    • The class should implementIterable<E> and define a method namediterator which makes use of thepersonList field to generate a new aIterator<E>.

Part 6.0 - TestPeople

  • Create aTestPeople class.
    • Create atestAdd method which ensures that ourpersonList in ourPeople class populated with respectivePerson objects following invokation of theadd method.
    • Create atestRemove method which ensures that thepersonList in aPeople object isdepopulated with a respectivePerson object following the invokation of theremove method.
    • Create atestFindById method which ensures that a respectivePerson object with a respectiveid field is returned upon invokation of thefindById method on a respectivePeople object.

Part 7.1 - CreateStudents singleton

  • Note: The creation of this class will demonstrate an implementation ofsingleton design pattern.
  • Create aStudents class.
    • The class should be anunextendable subclass of thePeople class.
    • The class shouldstatically instantiate afinal field namedINSTANCE of typeStudents.
    • The class should define aprivate nullary constructor which populates theINSTANCE field with respectiveStudent representations of your colleagues.
      • Each student should have arelatively uniqueid field.
    • The class should define agetInstance method which returns theINSTANCE field.

Part 7.0 - TestStudents singleton

  • Create aTestStudents class.
    • Create atest method which ensures that each of the students in your current cohort are in yourStudents singleton.

Part 8.0 - Create and TestInstructors singleton

  • UsePart 7 as a reference.
  • Create aInstructors singleton which represents the set of instructors at ZipCodeWilmington.
  • Create aTestInstructors class.

Part 9.1 - CreateZipCodeWilmington Class

  • Create aZipCodeWilmington singleton.
    • The class should declare a field that references the instance ofStudents calledstudents.
    • The class should declare a field that references the instance ofInstructors calledinstructors.
    • The class should define a methodhostLecture which makes use of aTeacher teacher, double numberOfHours parameter to host alecture to the compositepersonList field in thestudents reference.
    • The class should define a methodhostLecture 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 methodgetStudyMap which returns a new instance of amapping fromStudent objects toDouble objects, representative of each respective student'stotalStudyTime.

Part 9.0 - TestZipCodeWilmington

  • Create aTestZipCodeWilmington class.
    • Create atestHostLecture method which ensures that each of theStudent'stotalStudyTime instance variable is incremented by the specifiednumberOfHours upon invoking thehostLecture method.

Notice the Design Flaw - Odd Casting Issues

  • You may have noticed that thefindById, andhostLecture methods require an intermediatecasting trick.
  • To remedy this issue, we cangenerify thePeople class.

Part 10.1 - ModifyPeople class

  • Parameterize thePeople 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 classabstract.
    • Anabstract class cannot be instantiated; Its concrete implementation is deferred to its subclass.
  • Modifypeople field to enforce that is a container of objects of typeE.
  • Modify theadd method to ensure that it handles object of typeE.
  • Modify thefindById method to ensure that it returns an object of typeE.
  • Modify thegetArray 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.

Part 10.2 - ModifyPeople subclasses

  • Modify theStudents class signature to ensure that it is a subclass ofPeople of parameterized typeStudent.
  • Modify theInstructors class signature to ensure that it is a subclass ofPeople of parameterized typeInstructor.
  • Provide concrete implementations of thegetArray method in each of these classes.

Part 10.3 - RefactorZipCodeWilmington class

  • Refactor thehostLecture method in theZipCodeWilmington class by removing any intermediatecasting trick(s).

Part 10.0 - Test refactored classes.

  • Ensure that theTestStudents,TestInstructors,TestPeople,TestZipCodeWilmington classes were not affected by the refactor.

Notice the Design Flaw - Non-Intuitive Orientation

  • You may have noticed thatfindById makes it difficult to intuitively identifywhichPerson object is being returned. To remedy this issue, we can make use of anenum which manipulates a compositeinstructor object.

Part 11.1 - CreateEducator enum

  • Create an enum namedEducator.
    • The enum should implementTeacher.
    • The enum should have an enumeration for each of the instructors represented in theInstructors class.
    • Upon construction each enumeration of the enum should instantiate a respectiveInstructor and assign it to a finalinstructor field upon construction. Theinstructor should be added to theInstructors singleton.
    • Calls to theteach andlecture method should be deferred to the compositeinstructor reference.
    • The enum should have adouble timeWorked field which keeps track of the hours that theEducator has taught.

Part 11.0 - TestEducator

  • UsePart 5 as a reference.

Part 12.0 - TestZipCodeWilmington

  • Ensure thehostLecture method can handle objects of typeEducator.

About

Week 4 Project: Instructor, Student, Classroom

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors3

  •  
  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp