Kate Moore cd3bacefff done | 6 år sedan | |
---|---|---|
.idea | 6 år sedan | |
src | 6 år sedan | |
.gitignore | 7 år sedan | |
.project | 7 år sedan | |
README.md | 6 år sedan | |
interfaces-1.iml | 6 år sedan | |
pom.xml | 7 år sedan |
ZipCodeWilmington
class which mediates a composite Students
and Instructors
singleton reference.Person
PersonTest
class.
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
Person
class.Person
class, declare a final
field named id
of type long
.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
Person
class, declare a field named name
of type String
.Person
class should define a getName()
method which returns the Person
object's name
field.Person
class should define a setName()
method which sets the Person
object's name
field.Learner
InterfaceLearner
interface.
Learner
should declare one method signature:
learn
double numberOfHours
void
Student
StudentTest
class.
testImplementation
method that asserts that a Student
is an instanceof
a Learner
.
Student
classStudent
implements the Learner
interfacelearn
methodtestInheritance
method that asserts that a Student
is an instanceof
a Person
.
Student
class inherit from Person
testLearn
method that ensures a Student
's totalStudyTime
instance variable is incremented by the specified numberOfHours
by invoking the .learn
method.
Student
class, add a field called totalStudyTime
of type double
Student
class, implementate the learn
method which increments the totalStudyTime
variable by the specified numberOfHours
argument.`Student
class, add a getTotalStudyTime()
method which returns the totalStudyTime
instance variable.Teacher
InterfaceCreate a Teacher
interface.
Teacher
should declare a teach
method signature:
teach
Learner learner
double numberOfHours
void
Teacher
should declare a lecture
method signature:
lecture
Learner[] learners
double numberOfHours
void
Instructor
Create a InstructorTest
class.
Create a testImplementation
method that asserts that an Instructor
is an instanceof
a Teacher
.
Instructor
class such that:
Instructor
implements the Teacher
interface
Create a testInheritance
method that asserts that a Instructor
is an instanceof
a Person
.
Instructor
a subclass of Person
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
.
Instructor
class, add a concrete implementation of the teach
method which invokes the learn
method on the specified Learner
object.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
.
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.
numberOfHours
should be evenly split amongst the learners.
double numberOfHoursPerLearner = numberOfHours / learners.length;
People
PeopleTest
class.testAdd
method which ensures that our personList
in our People
class populated with respective Person
objects following invokation of the add
method.
People
class.People
class should instantiate an ArrayList
field of Person
objects named personList
.People
class should define a method named add
which adds a Person
to the personList
.People
class should define a method named getCount
which returns the size of personList
.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.
remove
which makes use of a Person person
parameter to remove a respective Person
object.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.
remove
which makes use of a long id
parameter to remove a Person
object with the respective id
field.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.
findById
which makes use of a long id
parameter to return a Person
object with the respective id
field.testGetArray
which ensures the array has all the people added
People
class, define a method named getArray
which returns an array representation of the personList
field.testRemoveAll
method which ensures you remove all the person added
People
class, define a method named removeAll
which clears our personList
field.Students
singletonStudents
will demonstrate an implementation of singleton design pattern.StudentsTest
class.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.
Students
class.People
class.final
field named INSTANCE
of type Students
.getInstance
method which returns the INSTANCE
field.testInitializationSetupStudents
method which ensures that each of the students in your current cohort are in your Students
singleton when getArray
is called.
Students
class, add all the students from your class so that calling getArray
will return all the students from your cohortid
field.Instructors
singletonPart 7
as a reference.InstructorsTest
class.Instructors
singleton which represents the set of instructors at ZipCodeWilmington.ZipCodeWilmington
ZipCodeWilmingtonTest
class.
testHostLecture
method which ensures that each of the Student
's totalStudyTime
instance variable is incremented by the specified numberOfHours
upon invoking the hostLecture
method.ZipCodeWilmington
singleton.
Students
called students
.Instructors
called instructors
.hostLecture
which makes use of a Teacher teacher, double numberOfHours
parameter to host a lecture
to the composite people
field in the students
reference.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.findById
, and hostLecture
methods require an intermediate casting trick.People
class.People
classPeople
signature to enforce that it is a container for objects of type E
such that E
is a subclass of Person
.people
field to enforce that is a container of objects of type E
.add
method to ensure that it handles object of type E
.findById
method to ensure that it returns an object of type E
.getArray
method signature by declaring it abstract
of return type E
.
-
People
subclassesStudents
class signature to ensure that it is a subclass of People
of parameterized type Student
.Instructors
class signature to ensure that it is a subclass of People
of parameterized type Instructor
.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
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[].-
ZipCodeWilmington
classhostLecture
method in the ZipCodeWilmington
class by removing any intermediate casting trick(s).-
StudentsTest
, InstructorsTest
, PeopleTest
, ZipCodeWilmingtonTest
classes were not affected by the refactor.-
findById
makes it difficult to intuitively identify which Person
object is being returned. To remedy this issue, we can make use of an enum
which manipulates a composite instructor
object.-
Educator
enumEducator
.
Teacher
.Instructors
class.teach
and lecture
method should be differed to the composite instructor
reference.double timeWorked
field which keeps track of the hours that the Educator
has taught.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.-
Educator
Part 5
as a reference.-
ZipCodeWilmington
hostLecture
method can handle objects of type Educator
.