From 3535fc4cb1bc849a2ca421d3a17c83400494150d Mon Sep 17 00:00:00 2001 From: Emmanuel Orubele Date: Wed, 22 Jul 2020 23:49:46 -0400 Subject: [PATCH 1/5] Week 6 Assignment --- .../com/github/curriculeon/Instructor.java | 22 ++++++ .../java/com/github/curriculeon/Learner.java | 7 ++ .../java/com/github/curriculeon/People.java | 62 +++++++++++++++ .../java/com/github/curriculeon/Person.java | 26 ++++++ .../java/com/github/curriculeon/Student.java | 20 +++++ .../java/com/github/curriculeon/Teacher.java | 7 ++ .../github/curriculeon/TestInstructor.java | 79 +++++++++++++++++++ .../com/github/curriculeon/TestPeople.java | 74 +++++++++++++++++ .../com/github/curriculeon/TestPerson.java | 41 ++++++++++ .../com/github/curriculeon/TestStudent.java | 39 +++++++++ 10 files changed, 377 insertions(+) create mode 100644 src/main/java/com/github/curriculeon/Instructor.java create mode 100644 src/main/java/com/github/curriculeon/Learner.java create mode 100644 src/main/java/com/github/curriculeon/People.java create mode 100644 src/main/java/com/github/curriculeon/Student.java create mode 100644 src/main/java/com/github/curriculeon/Teacher.java create mode 100644 src/test/java/com/github/curriculeon/TestInstructor.java create mode 100644 src/test/java/com/github/curriculeon/TestPeople.java create mode 100644 src/test/java/com/github/curriculeon/TestStudent.java diff --git a/src/main/java/com/github/curriculeon/Instructor.java b/src/main/java/com/github/curriculeon/Instructor.java new file mode 100644 index 0000000..1ba5d27 --- /dev/null +++ b/src/main/java/com/github/curriculeon/Instructor.java @@ -0,0 +1,22 @@ +package com.github.curriculeon; + +public class Instructor extends Person implements Teacher { + + public Instructor(Long id, String name) { + super(id, name); + } + + @Override + public void teach(Learner learner, Double numberOfHours) { + learner.learn(numberOfHours); + } + + @Override + public void lecture(Learner[] learners, Double numberOfHours) { + double numberOfHoursPerLearner = numberOfHours / learners.length; + for (int i = 0; i < learners.length; i++) { + Learner learner = learners[i]; + learner.learn(numberOfHoursPerLearner); + } + } +} diff --git a/src/main/java/com/github/curriculeon/Learner.java b/src/main/java/com/github/curriculeon/Learner.java new file mode 100644 index 0000000..ed44af1 --- /dev/null +++ b/src/main/java/com/github/curriculeon/Learner.java @@ -0,0 +1,7 @@ +package com.github.curriculeon; + +public interface Learner { + + void learn(Double numberOfHours); + double getTotalStudyTime(); +} diff --git a/src/main/java/com/github/curriculeon/People.java b/src/main/java/com/github/curriculeon/People.java new file mode 100644 index 0000000..7e42234 --- /dev/null +++ b/src/main/java/com/github/curriculeon/People.java @@ -0,0 +1,62 @@ +package com.github.curriculeon; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +public class People implements Iterable{ + List personList= new ArrayList<>(); + + public void add(Person personToAdd){ + personList.add(personToAdd); + + } + + public Person findById(Long id) { + for (Person person : personList) { + if (person.getId() == id) { + return person; + } + + }// for + return null; + }// findById + + + public boolean contains(Person person){ + return personList.contains(person); //returns true if the object passed contains person. + } + + public void remove(Person person) { + personList.remove(person); + } + + public void remove(Long id) { + for (Person person : personList) { + if (person.getId() == id) { + personList.remove(id); + } + } + + } + + public void removeAll(){ + personList.clear(); + } + + + public Integer count(){ + return personList.size(); + } + + public Person[] toArray(){ + return personList.toArray(new Person[personList.size()]); + + } + + @Override + public Iterator iterator(){ + return personList.iterator(); + } +}//class diff --git a/src/main/java/com/github/curriculeon/Person.java b/src/main/java/com/github/curriculeon/Person.java index 3c8350b..ca08879 100644 --- a/src/main/java/com/github/curriculeon/Person.java +++ b/src/main/java/com/github/curriculeon/Person.java @@ -1,5 +1,31 @@ package com.github.curriculeon; +/* + * Created By Emmanuel Orubele + * on 7/21/2020 + */ + public class Person { + private final Long id; + private String name; + +public Person() { + this.id = getId(); +} + public Person(Long id, String name){ + this.id = id; + this.name = name; + } + + public Long getId() { + return id; + } + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } } diff --git a/src/main/java/com/github/curriculeon/Student.java b/src/main/java/com/github/curriculeon/Student.java new file mode 100644 index 0000000..ed5ccec --- /dev/null +++ b/src/main/java/com/github/curriculeon/Student.java @@ -0,0 +1,20 @@ +package com.github.curriculeon; + +public class Student extends Person implements Learner{ + + private double totalStudyTime; + public Student(Long id, String name) { + super(id, name); + } + + @Override + public void learn(Double numberOfHours) { + totalStudyTime += numberOfHours; + + } + + @Override + public double getTotalStudyTime() { + return totalStudyTime; + } +} diff --git a/src/main/java/com/github/curriculeon/Teacher.java b/src/main/java/com/github/curriculeon/Teacher.java new file mode 100644 index 0000000..c1eba39 --- /dev/null +++ b/src/main/java/com/github/curriculeon/Teacher.java @@ -0,0 +1,7 @@ +package com.github.curriculeon; + +interface Teacher { + void teach(Learner learner, Double numberOfHours); + void lecture(Learner[] learners, Double numberOfHours); + +} diff --git a/src/test/java/com/github/curriculeon/TestInstructor.java b/src/test/java/com/github/curriculeon/TestInstructor.java new file mode 100644 index 0000000..6511903 --- /dev/null +++ b/src/test/java/com/github/curriculeon/TestInstructor.java @@ -0,0 +1,79 @@ +package com.github.curriculeon; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.function.DoubleUnaryOperator; + +public class TestInstructor { + + @Test + public void testImplementation(){ + //Given + Instructor instructor = new Instructor(null, null); + + //When + boolean expected = instructor instanceof Teacher; + + //Then + Assert.assertTrue(expected); + } + + @Test + public void testInheritance(){ + //Given + Instructor instructor = new Instructor(null, null); + + //When + boolean expected = instructor instanceof Person; + + //Then + Assert.assertTrue(expected); + + } + + @Test + public void testTeach(){ + //Given + Instructor instructor = new Instructor(null, null); + Learner learn = new Student(null, null); + Double numberOfTeachingHours = 90.0d; + Double hours = learn.getTotalStudyTime(); + Double expected = hours + numberOfTeachingHours ; + //When + instructor.teach(learn, numberOfTeachingHours); + Double actual = learn.getTotalStudyTime(); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testLecture(){ + //Given + Teacher instructor = new Instructor(null, null); + Double numberHours = 134d; + Learner[] learn = new Learner[] { + new Student(22l, "Emmanuel"), + new Student(23l, "Mike"), + new Student(24l, "Leon") + }; + + Double expected = numberHours/learn.length; + + + + //When + instructor.lecture(learn, numberHours); + + + //Then + for (int i = 0; i < learn.length; i++) { + Learner learner = learn[i]; + Double actual = learner.getTotalStudyTime(); + + Assert.assertEquals(expected, actual); + + } + } +} diff --git a/src/test/java/com/github/curriculeon/TestPeople.java b/src/test/java/com/github/curriculeon/TestPeople.java new file mode 100644 index 0000000..63f7cd8 --- /dev/null +++ b/src/test/java/com/github/curriculeon/TestPeople.java @@ -0,0 +1,74 @@ +package com.github.curriculeon; + +import org.junit.Assert; +import org.junit.Test; + +public class TestPeople { + /**? + * Credits to Leon Christopher Hunter for all the help in building this project. + * Without Leon there would be no java project by me. + */ + + @Test + public void testAdd(){ + //Given + People people = new People(); + + Person people1 = new Person(); + Person people2 = new Person(); + Assert.assertFalse(people.contains(people1)); + Assert.assertFalse(people.contains(people2)); + + //When + people.add(people1); + people.add(people2); + //Then + + Assert.assertTrue(people.contains(people1)); + Assert.assertTrue(people.contains(people2)); + } + + @Test + public void testRemove(){ + //Given + People people = new People(); + Person people1 = new Person(); + Person people2 =new Person(); + + people.add(people1); + people.add(people2); + + Assert.assertTrue(people.contains(people1)); + Assert.assertTrue(people.contains(people2)); + + //When + people.remove(people1); + people.remove(people2); + + //Then + Assert.assertFalse(people.contains(people1)); + Assert.assertFalse(people.contains(people2)); + } + + @Test + public void testFindById() { + //Given + People people = new People(); + Person expected = new Person(22l, "Emmanuel"); + Person people2 =new Person(23l, "Johnson"); + + people.add(expected); + people.add(people2); + + Assert.assertTrue(people.contains(expected)); + Assert.assertTrue(people.contains(people2)); + + //When + Person actual = people.findById(22l); + + + //Then + Assert.assertEquals(expected, actual); + } + +} diff --git a/src/test/java/com/github/curriculeon/TestPerson.java b/src/test/java/com/github/curriculeon/TestPerson.java index 6c523fe..b1b9c76 100644 --- a/src/test/java/com/github/curriculeon/TestPerson.java +++ b/src/test/java/com/github/curriculeon/TestPerson.java @@ -1,5 +1,46 @@ package com.github.curriculeon; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + public class TestPerson { + private void testConstructor(long expectedLong, String expectedString){ + // : Given + Person person = new Person(expectedLong, expectedString); + + + // : When + long actualLong = person.getId(); + String actualString = person.getName(); + + // : Then + assertEquals(expectedLong, actualLong); + assertEquals(expectedString, actualString); + + } + + @Test + public void test0(){ testConstructor(20, "abc"); } + +@Test + public void test1(){testConstructor(10, "Hello World");} + + +@Test + public void testSetName(){ + //Given + Person p = new Person(12l, "abced"); + + // When + String testName = "wwww"; + p.setName(testName); + + + //then + assertEquals(p.getName(), p.getName()); + + } + } diff --git a/src/test/java/com/github/curriculeon/TestStudent.java b/src/test/java/com/github/curriculeon/TestStudent.java new file mode 100644 index 0000000..2c80d7c --- /dev/null +++ b/src/test/java/com/github/curriculeon/TestStudent.java @@ -0,0 +1,39 @@ +package com.github.curriculeon; + +import org.junit.Assert; +import org.junit.Test; + +public class TestStudent { + + @Test + public void testImplementation(){ + //Given + Student student = new Student(null, null); + // when + boolean expected = student instanceof Learner; + //then + Assert.assertTrue(expected); + } + + @Test + public void testInheritance(){ + Assert.assertTrue(new Student(null, null) instanceof Person); + } + + + @Test + public void testLearn(){ + //Given + Student student = new Student(20l, "Emmanuel"); + Double studentStudyTime = 40.0; + Double preStudy = student.getTotalStudyTime(); + Double expected = studentStudyTime + preStudy; + //When + student.learn(studentStudyTime); + Double actual = student.getTotalStudyTime(); + + //then + + Assert.assertEquals(expected,actual); + } +} From df5bb7064b040013dcc0db1111a9dfe9090b6da1 Mon Sep 17 00:00:00 2001 From: Emmanuel Orubele Date: Sat, 25 Jul 2020 01:41:46 -0400 Subject: [PATCH 2/5] 7, 8 completed --- src/main/java/com/github/curriculeon/Classroom.java | 4 ++++ src/main/java/com/github/curriculeon/Instructors.java | 4 ++++ src/main/java/com/github/curriculeon/Students.java | 4 ++++ src/test/java/com/github/curriculeon/TestInstructors.java | 4 ++++ src/test/java/com/github/curriculeon/TestStudents.java | 4 ++++ 5 files changed, 20 insertions(+) create mode 100644 src/main/java/com/github/curriculeon/Classroom.java create mode 100644 src/main/java/com/github/curriculeon/Instructors.java create mode 100644 src/main/java/com/github/curriculeon/Students.java create mode 100644 src/test/java/com/github/curriculeon/TestInstructors.java create mode 100644 src/test/java/com/github/curriculeon/TestStudents.java diff --git a/src/main/java/com/github/curriculeon/Classroom.java b/src/main/java/com/github/curriculeon/Classroom.java new file mode 100644 index 0000000..6a949d5 --- /dev/null +++ b/src/main/java/com/github/curriculeon/Classroom.java @@ -0,0 +1,4 @@ +package com.github.curriculeon; + +public class Classroom { +} diff --git a/src/main/java/com/github/curriculeon/Instructors.java b/src/main/java/com/github/curriculeon/Instructors.java new file mode 100644 index 0000000..64710c4 --- /dev/null +++ b/src/main/java/com/github/curriculeon/Instructors.java @@ -0,0 +1,4 @@ +package com.github.curriculeon; + +public class Instructors { +} diff --git a/src/main/java/com/github/curriculeon/Students.java b/src/main/java/com/github/curriculeon/Students.java new file mode 100644 index 0000000..284cb96 --- /dev/null +++ b/src/main/java/com/github/curriculeon/Students.java @@ -0,0 +1,4 @@ +package com.github.curriculeon; + +public class Students { +} diff --git a/src/test/java/com/github/curriculeon/TestInstructors.java b/src/test/java/com/github/curriculeon/TestInstructors.java new file mode 100644 index 0000000..ffdf019 --- /dev/null +++ b/src/test/java/com/github/curriculeon/TestInstructors.java @@ -0,0 +1,4 @@ +package com.github.curriculeon; + +public class TestInstructors { +} diff --git a/src/test/java/com/github/curriculeon/TestStudents.java b/src/test/java/com/github/curriculeon/TestStudents.java new file mode 100644 index 0000000..17f8259 --- /dev/null +++ b/src/test/java/com/github/curriculeon/TestStudents.java @@ -0,0 +1,4 @@ +package com.github.curriculeon; + +public class TestStudents { +} From 78a07dc216bc51a220c6a686b60a1b64ee89c5f8 Mon Sep 17 00:00:00 2001 From: Emmanuel Orubele Date: Wed, 29 Jul 2020 21:18:32 -0400 Subject: [PATCH 3/5] changes to part 9 --- .../com/github/curriculeon/Classroom.java | 32 +++++++++++++++++++ .../com/github/curriculeon/Instructors.java | 17 +++++++++- .../java/com/github/curriculeon/Students.java | 19 ++++++++++- .../com/github/curriculeon/TestClassroom.java | 24 ++++++++++++++ .../github/curriculeon/TestInstructors.java | 20 ++++++++++++ .../com/github/curriculeon/TestStudents.java | 16 ++++++++++ 6 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 src/test/java/com/github/curriculeon/TestClassroom.java diff --git a/src/main/java/com/github/curriculeon/Classroom.java b/src/main/java/com/github/curriculeon/Classroom.java index 6a949d5..cde48e9 100644 --- a/src/main/java/com/github/curriculeon/Classroom.java +++ b/src/main/java/com/github/curriculeon/Classroom.java @@ -1,4 +1,36 @@ package com.github.curriculeon; +import java.util.HashMap; +import java.util.Map; + public class Classroom { + private final static Classroom instance = new Classroom(); + private Students students = Students.getINSTANCE(); + private Instructors instructors = Instructors.getINSTANCE(); + + public static Classroom getClassroom(){ + return instance; + } + + public void hostLecture(Teacher teacher, Double numbersOfHours){ + teacher.lecture((Learner[])students.toArray(), numbersOfHours); + + } + + + public void hostLecture(Long id, Double numberOfHours){ + Person person = instructors.findById(id); + Instructor instructor = (Instructor)person; + instructor.lecture((Learner[])students.toArray(), numberOfHours); + } + + public Map getStudyMap(){ + Map result = new HashMap<>(); + for (Person studentAsperson : students.toArray()) { + Student student = (Student)studentAsperson; + Double studyTime = student.getTotalStudyTime(); + } + return result; + } + } diff --git a/src/main/java/com/github/curriculeon/Instructors.java b/src/main/java/com/github/curriculeon/Instructors.java index 64710c4..96e3b07 100644 --- a/src/main/java/com/github/curriculeon/Instructors.java +++ b/src/main/java/com/github/curriculeon/Instructors.java @@ -1,4 +1,19 @@ package com.github.curriculeon; -public class Instructors { + +public class Instructors extends People { + private static final Instructors INSTANCE = new Instructors(); + + + public People myInstructor = new People(); + private Instructors(){ + this.add( new Instructor(01l, "Leon")); + this.add(new Instructor (02l,"Christel")); + + } + + + public static Instructors getINSTANCE(){ + return INSTANCE; + } } diff --git a/src/main/java/com/github/curriculeon/Students.java b/src/main/java/com/github/curriculeon/Students.java index 284cb96..6aaba84 100644 --- a/src/main/java/com/github/curriculeon/Students.java +++ b/src/main/java/com/github/curriculeon/Students.java @@ -1,4 +1,21 @@ package com.github.curriculeon; -public class Students { +public class Students extends People { + private static final Students INSTANCE = new Students(); + //private Map mates = new HashMap(); + // tried to use a hash map. + + People myColleagues = new People(); + private Students(){ + + Student firstStudent = new Student(10l, "Christopher"); + Student secondStudent = new Student(15l, "David"); + myColleagues.add(secondStudent); + myColleagues.add(firstStudent); + + } + + public static Students getINSTANCE(){ + return INSTANCE; + } } diff --git a/src/test/java/com/github/curriculeon/TestClassroom.java b/src/test/java/com/github/curriculeon/TestClassroom.java new file mode 100644 index 0000000..49886c4 --- /dev/null +++ b/src/test/java/com/github/curriculeon/TestClassroom.java @@ -0,0 +1,24 @@ +package com.github.curriculeon; + + +import org.junit.Assert; +import org.junit.Test; + +public class TestClassroom { + + + @Test + public void testHostLecture(){ + //Given + Classroom classroom = Classroom.getClassroom(); + Teacher teacher = Instructors.getINSTANCE().findById(2l); + + //When + classroom.hostLecture(studentId, expected); + + + //Then + Assert.assertEquals(expected); + + } +} diff --git a/src/test/java/com/github/curriculeon/TestInstructors.java b/src/test/java/com/github/curriculeon/TestInstructors.java index ffdf019..6b6a9c0 100644 --- a/src/test/java/com/github/curriculeon/TestInstructors.java +++ b/src/test/java/com/github/curriculeon/TestInstructors.java @@ -1,4 +1,24 @@ package com.github.curriculeon; +import org.junit.Assert; +import org.junit.Test; + public class TestInstructors { + + @Test + public void instructorsSingletonTest(){ + + //Given + Instructors instructor = Instructors.getINSTANCE(); + String expected = "Leon"; + + //When + String actual = instructor.myInstructor.findById(01l).getName(); + //Then + + Assert.assertEquals(expected, actual); + actual = instructor.myInstructor.findById(02l).getName(); + Assert.assertEquals("Christel", actual); + } + } diff --git a/src/test/java/com/github/curriculeon/TestStudents.java b/src/test/java/com/github/curriculeon/TestStudents.java index 17f8259..13d6607 100644 --- a/src/test/java/com/github/curriculeon/TestStudents.java +++ b/src/test/java/com/github/curriculeon/TestStudents.java @@ -1,4 +1,20 @@ package com.github.curriculeon; +import org.junit.Assert; +import org.junit.Test; + public class TestStudents { + + @Test + public void test(){ + //Given + Students students = Students.getINSTANCE(); + String expectedStudentName = "David"; + + + //Then + String actual = students.myColleagues.findById(15l).getName(); + //When + Assert.assertEquals(expectedStudentName, actual); + } } From 1d082f7264d2afc5d52236d55f1a6f6696a85c33 Mon Sep 17 00:00:00 2001 From: Emmanuel Orubele Date: Fri, 31 Jul 2020 01:52:51 -0400 Subject: [PATCH 4/5] learner lab 10, 11.1, and 12 --- .../com/github/curriculeon/Classroom.java | 4 +-- .../com/github/curriculeon/Instructors.java | 15 ++++++-- .../java/com/github/curriculeon/People.java | 36 ++++++++++--------- .../java/com/github/curriculeon/Students.java | 20 +++++++---- .../com/github/curriculeon/TestClassroom.java | 23 ++++++++++-- .../github/curriculeon/TestInstructors.java | 4 +-- .../com/github/curriculeon/TestPeople.java | 6 ++-- .../com/github/curriculeon/TestStudents.java | 2 +- 8 files changed, 74 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/github/curriculeon/Classroom.java b/src/main/java/com/github/curriculeon/Classroom.java index cde48e9..87c934b 100644 --- a/src/main/java/com/github/curriculeon/Classroom.java +++ b/src/main/java/com/github/curriculeon/Classroom.java @@ -13,7 +13,7 @@ public static Classroom getClassroom(){ } public void hostLecture(Teacher teacher, Double numbersOfHours){ - teacher.lecture((Learner[])students.toArray(), numbersOfHours); + teacher.lecture(students.toArray(), numbersOfHours); } @@ -21,7 +21,7 @@ public void hostLecture(Teacher teacher, Double numbersOfHours){ public void hostLecture(Long id, Double numberOfHours){ Person person = instructors.findById(id); Instructor instructor = (Instructor)person; - instructor.lecture((Learner[])students.toArray(), numberOfHours); + instructor.lecture(students.toArray(), numberOfHours); } public Map getStudyMap(){ diff --git a/src/main/java/com/github/curriculeon/Instructors.java b/src/main/java/com/github/curriculeon/Instructors.java index 96e3b07..c2cff7d 100644 --- a/src/main/java/com/github/curriculeon/Instructors.java +++ b/src/main/java/com/github/curriculeon/Instructors.java @@ -1,17 +1,26 @@ package com.github.curriculeon; -public class Instructors extends People { +import java.util.List; + +public class Instructors extends People { private static final Instructors INSTANCE = new Instructors(); - public People myInstructor = new People(); - private Instructors(){ + public Instructors(){ this.add( new Instructor(01l, "Leon")); this.add(new Instructor (02l,"Christel")); } + @Override + public Instructor[] toArray() { + int arrCount = count(); + Instructor[] destinationArr = new Instructor[arrCount]; + List instructorList = personList; + return instructorList.toArray(destinationArr); + } + public static Instructors getINSTANCE(){ return INSTANCE; diff --git a/src/main/java/com/github/curriculeon/People.java b/src/main/java/com/github/curriculeon/People.java index 7e42234..e5a47a6 100644 --- a/src/main/java/com/github/curriculeon/People.java +++ b/src/main/java/com/github/curriculeon/People.java @@ -5,35 +5,42 @@ import java.util.Iterator; import java.util.List; -public class People implements Iterable{ - List personList= new ArrayList<>(); +abstract class People implements Iterable{ + List personList; + public People(){ + new ArrayList<>(); + } - public void add(Person personToAdd){ + public People(List personList){ + this.personList = personList; + } + public void add(somePeople personToAdd){ personList.add(personToAdd); - } - public Person findById(Long id) { - for (Person person : personList) { - if (person.getId() == id) { + public somePeople findById(Long id) { + for (int i = 0; i < personList.size() ; i++) { + somePeople person = personList.get(i); + if (person.getId() == id){// check if the person exist. return person; + }else { + continue; // keep looking until id is found } - }// for return null; }// findById - public boolean contains(Person person){ + public boolean contains(somePeople person){ return personList.contains(person); //returns true if the object passed contains person. } - public void remove(Person person) { + public void remove(somePeople person) { personList.remove(person); } public void remove(Long id) { - for (Person person : personList) { + for (somePeople person : personList) { if (person.getId() == id) { personList.remove(id); } @@ -50,13 +57,10 @@ public Integer count(){ return personList.size(); } - public Person[] toArray(){ - return personList.toArray(new Person[personList.size()]); - - } + abstract public somePeople[] toArray(); @Override - public Iterator iterator(){ + public Iterator iterator(){ return personList.iterator(); } }//class diff --git a/src/main/java/com/github/curriculeon/Students.java b/src/main/java/com/github/curriculeon/Students.java index 6aaba84..6ab5edc 100644 --- a/src/main/java/com/github/curriculeon/Students.java +++ b/src/main/java/com/github/curriculeon/Students.java @@ -1,17 +1,25 @@ package com.github.curriculeon; -public class Students extends People { +import java.util.List; + +public class Students extends People { private static final Students INSTANCE = new Students(); //private Map mates = new HashMap(); // tried to use a hash map. - People myColleagues = new People(); private Students(){ + this.add(new Student(10l, "Christopher")); + this.add( new Student(15l, "David")); + + + } - Student firstStudent = new Student(10l, "Christopher"); - Student secondStudent = new Student(15l, "David"); - myColleagues.add(secondStudent); - myColleagues.add(firstStudent); + @Override + public Student[] toArray() { + int arraySize = count(); + Student[] destinationArr = new Student[arraySize]; + List sourceList = personList; + return sourceList.toArray(destinationArr); } diff --git a/src/test/java/com/github/curriculeon/TestClassroom.java b/src/test/java/com/github/curriculeon/TestClassroom.java index 49886c4..a52a607 100644 --- a/src/test/java/com/github/curriculeon/TestClassroom.java +++ b/src/test/java/com/github/curriculeon/TestClassroom.java @@ -4,6 +4,9 @@ import org.junit.Assert; import org.junit.Test; +import java.util.Map; +import java.util.Set; + public class TestClassroom { @@ -12,13 +15,27 @@ public void testHostLecture(){ //Given Classroom classroom = Classroom.getClassroom(); Teacher teacher = Instructors.getINSTANCE().findById(2l); + Integer numberOfStudents = Students.getINSTANCE().count(); + Double numberOfHoursToLecture = numberOfStudents.doubleValue(); + Double expectedNumberOfHours = numberOfHoursToLecture / numberOfStudents; + Map preStudyMap = classroom.getStudyMap(); //When - classroom.hostLecture(studentId, expected); + classroom.hostLecture(teacher, numberOfHoursToLecture); + Map postStudyMap = classroom.getStudyMap(); + Set keySet = postStudyMap.keySet(); + for (Student student : keySet) { + Double preStudyTime = preStudyMap.get(student); + Double expectedStudyTime = preStudyTime + expectedNumberOfHours; + Double actualStudyTime = postStudyMap.get(student); + + + + //Then + Assert.assertEquals(expectedStudyTime, actualStudyTime); + } - //Then - Assert.assertEquals(expected); } } diff --git a/src/test/java/com/github/curriculeon/TestInstructors.java b/src/test/java/com/github/curriculeon/TestInstructors.java index 6b6a9c0..eab21be 100644 --- a/src/test/java/com/github/curriculeon/TestInstructors.java +++ b/src/test/java/com/github/curriculeon/TestInstructors.java @@ -13,11 +13,11 @@ public void instructorsSingletonTest(){ String expected = "Leon"; //When - String actual = instructor.myInstructor.findById(01l).getName(); + String actual = instructor.findById(01l).getName(); //Then Assert.assertEquals(expected, actual); - actual = instructor.myInstructor.findById(02l).getName(); + actual = instructor.findById(02l).getName(); Assert.assertEquals("Christel", actual); } diff --git a/src/test/java/com/github/curriculeon/TestPeople.java b/src/test/java/com/github/curriculeon/TestPeople.java index 63f7cd8..eeb8484 100644 --- a/src/test/java/com/github/curriculeon/TestPeople.java +++ b/src/test/java/com/github/curriculeon/TestPeople.java @@ -12,7 +12,7 @@ public class TestPeople { @Test public void testAdd(){ //Given - People people = new People(); + People people = Instructors.getINSTANCE(); Person people1 = new Person(); Person people2 = new Person(); @@ -31,7 +31,7 @@ public void testAdd(){ @Test public void testRemove(){ //Given - People people = new People(); + People people = Instructors.getINSTANCE(); Person people1 = new Person(); Person people2 =new Person(); @@ -53,7 +53,7 @@ public void testRemove(){ @Test public void testFindById() { //Given - People people = new People(); + People people = Instructors.getINSTANCE(); Person expected = new Person(22l, "Emmanuel"); Person people2 =new Person(23l, "Johnson"); diff --git a/src/test/java/com/github/curriculeon/TestStudents.java b/src/test/java/com/github/curriculeon/TestStudents.java index 13d6607..3d5d39a 100644 --- a/src/test/java/com/github/curriculeon/TestStudents.java +++ b/src/test/java/com/github/curriculeon/TestStudents.java @@ -13,7 +13,7 @@ public void test(){ //Then - String actual = students.myColleagues.findById(15l).getName(); + String actual = students.findById(15l).getName(); //When Assert.assertEquals(expectedStudentName, actual); } From 989c18c545e53f09bbf5d1a876996601ba942d26 Mon Sep 17 00:00:00 2001 From: Emmanuel Orubele Date: Sat, 1 Aug 2020 21:03:04 -0400 Subject: [PATCH 5/5] part 11-12 --- .../java/com/github/curriculeon/Educator.java | 30 +++++++++++++++++++ .../com/github/curriculeon/Instructors.java | 4 +-- .../com/github/curriculeon/TestPeople.java | 4 --- 3 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/github/curriculeon/Educator.java diff --git a/src/main/java/com/github/curriculeon/Educator.java b/src/main/java/com/github/curriculeon/Educator.java new file mode 100644 index 0000000..3653bf6 --- /dev/null +++ b/src/main/java/com/github/curriculeon/Educator.java @@ -0,0 +1,30 @@ +package com.github.curriculeon; + +public enum Educator implements Teacher { + + LEON, + HASEEB; + + private Double timeWorked; + private final Instructor instructor; + + Educator(){ + long id = this.ordinal(); + String name = this.name();// get instructors name. + this.instructor = new Instructor(id, name); + Instructors.getINSTANCE().add(instructor); + } + + ; + @Override + public void teach(Learner learner, Double numberOfHours) { + instructor.teach(learner, numberOfHours); + timeWorked += numberOfHours; + } + + @Override + public void lecture(Learner[] learners, Double numberOfHours) { + instructor.lecture(learners, numberOfHours); + timeWorked += numberOfHours; + } +} diff --git a/src/main/java/com/github/curriculeon/Instructors.java b/src/main/java/com/github/curriculeon/Instructors.java index c2cff7d..3fbdd14 100644 --- a/src/main/java/com/github/curriculeon/Instructors.java +++ b/src/main/java/com/github/curriculeon/Instructors.java @@ -8,8 +8,8 @@ public class Instructors extends People { public Instructors(){ - this.add( new Instructor(01l, "Leon")); - this.add(new Instructor (02l,"Christel")); + this.add( new Instructor(0l, "Leon")); + this.add(new Instructor (1l,"Christel")); } diff --git a/src/test/java/com/github/curriculeon/TestPeople.java b/src/test/java/com/github/curriculeon/TestPeople.java index eeb8484..b3ebc88 100644 --- a/src/test/java/com/github/curriculeon/TestPeople.java +++ b/src/test/java/com/github/curriculeon/TestPeople.java @@ -15,17 +15,13 @@ public void testAdd(){ People people = Instructors.getINSTANCE(); Person people1 = new Person(); - Person people2 = new Person(); Assert.assertFalse(people.contains(people1)); - Assert.assertFalse(people.contains(people2)); //When people.add(people1); - people.add(people2); //Then Assert.assertTrue(people.contains(people1)); - Assert.assertTrue(people.contains(people2)); } @Test