From 139fe6583d9cc90a6a3ff3c55ae0d84316a9ca87 Mon Sep 17 00:00:00 2001 From: razeroual <47251928+razeroual@users.noreply.github.com> Date: Mon, 20 Jul 2020 15:14:07 -0400 Subject: [PATCH 01/10] done Part 1 --- .../java/com/github/curriculeon/Person.java | 18 ++++++ .../com/github/curriculeon/SetNameTest.java | 59 +++++++++++++++++++ .../com/github/curriculeon/TestPerson.java | 5 ++ 3 files changed, 82 insertions(+) create mode 100644 src/test/java/com/github/curriculeon/SetNameTest.java diff --git a/src/main/java/com/github/curriculeon/Person.java b/src/main/java/com/github/curriculeon/Person.java index 3c8350b..0d1e146 100644 --- a/src/main/java/com/github/curriculeon/Person.java +++ b/src/main/java/com/github/curriculeon/Person.java @@ -1,5 +1,23 @@ package com.github.curriculeon; public class Person { + final long id ; + private String name; + 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/test/java/com/github/curriculeon/SetNameTest.java b/src/test/java/com/github/curriculeon/SetNameTest.java new file mode 100644 index 0000000..b3b5b51 --- /dev/null +++ b/src/test/java/com/github/curriculeon/SetNameTest.java @@ -0,0 +1,59 @@ +package com.github.curriculeon; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by leon on 7/15/2020. + */ +public class SetNameTest { + private void test(String expected) { + // Given + Person person = new Person(55555557, "someName"); + + // When + person.setName(expected); + String actual = person.getName(); + + // Then + Assert.assertEquals(expected, actual); + } + + @Test + public void test0() { + test(null); + } + + + @Test + public void test1() { + test("Dan Winter"); + } + + + + @Test + public void test2() { + test("David Berlinski"); + } + + + + @Test + public void test3() { + test("Steven C Meyers"); + } + + + + @Test + public void test4() { + test("Heart Harmonics"); + } + + + @Test + public void test5() { + test("Phase Conjugate Negentropic Charge Collapse"); + } +} diff --git a/src/test/java/com/github/curriculeon/TestPerson.java b/src/test/java/com/github/curriculeon/TestPerson.java index 6c523fe..870c132 100644 --- a/src/test/java/com/github/curriculeon/TestPerson.java +++ b/src/test/java/com/github/curriculeon/TestPerson.java @@ -1,5 +1,10 @@ package com.github.curriculeon; +import org.junit.Test; + public class TestPerson { + @Test + public void name() { + } } From ef36962fdc2734a5d275959135c53d245656f8ac Mon Sep 17 00:00:00 2001 From: razeroual <47251928+razeroual@users.noreply.github.com> Date: Mon, 20 Jul 2020 15:16:10 -0400 Subject: [PATCH 02/10] update class person --- src/main/java/com/github/curriculeon/Person.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/github/curriculeon/Person.java b/src/main/java/com/github/curriculeon/Person.java index 0d1e146..131a011 100644 --- a/src/main/java/com/github/curriculeon/Person.java +++ b/src/main/java/com/github/curriculeon/Person.java @@ -1,7 +1,7 @@ package com.github.curriculeon; public class Person { - final long id ; + private final long id; private String name; public Person(long id, String name) { From 10e1be4e83ee3c8a02da422c07161b3ffb2caae1 Mon Sep 17 00:00:00 2001 From: razeroual <47251928+razeroual@users.noreply.github.com> Date: Tue, 21 Jul 2020 11:51:35 -0400 Subject: [PATCH 03/10] update TestPerson --- .../java/com/github/curriculeon/Person.java | 6 +- .../com/github/curriculeon/SetNameTest.java | 59 ------------------- .../com/github/curriculeon/TestPerson.java | 29 ++++++++- 3 files changed, 31 insertions(+), 63 deletions(-) delete mode 100644 src/test/java/com/github/curriculeon/SetNameTest.java diff --git a/src/main/java/com/github/curriculeon/Person.java b/src/main/java/com/github/curriculeon/Person.java index 131a011..5fc7883 100644 --- a/src/main/java/com/github/curriculeon/Person.java +++ b/src/main/java/com/github/curriculeon/Person.java @@ -1,15 +1,15 @@ package com.github.curriculeon; public class Person { - private final long id; + private final Long id; private String name; - public Person(long id, String name) { + public Person(Long id, String name) { this.id = id; this.name = name; } - public long getId() { + public Long getId() { return id; } diff --git a/src/test/java/com/github/curriculeon/SetNameTest.java b/src/test/java/com/github/curriculeon/SetNameTest.java deleted file mode 100644 index b3b5b51..0000000 --- a/src/test/java/com/github/curriculeon/SetNameTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.github.curriculeon; - -import org.junit.Assert; -import org.junit.Test; - -/** - * Created by leon on 7/15/2020. - */ -public class SetNameTest { - private void test(String expected) { - // Given - Person person = new Person(55555557, "someName"); - - // When - person.setName(expected); - String actual = person.getName(); - - // Then - Assert.assertEquals(expected, actual); - } - - @Test - public void test0() { - test(null); - } - - - @Test - public void test1() { - test("Dan Winter"); - } - - - - @Test - public void test2() { - test("David Berlinski"); - } - - - - @Test - public void test3() { - test("Steven C Meyers"); - } - - - - @Test - public void test4() { - test("Heart Harmonics"); - } - - - @Test - public void test5() { - test("Phase Conjugate Negentropic Charge Collapse"); - } -} diff --git a/src/test/java/com/github/curriculeon/TestPerson.java b/src/test/java/com/github/curriculeon/TestPerson.java index 870c132..38be440 100644 --- a/src/test/java/com/github/curriculeon/TestPerson.java +++ b/src/test/java/com/github/curriculeon/TestPerson.java @@ -1,10 +1,37 @@ package com.github.curriculeon; +import org.junit.Assert; import org.junit.Test; public class TestPerson { @Test - public void name() { + public void testConstructor() { + //Given + Long expectedId = 4212121L; + String expectedName = "SomeName"; + // When + Person person = new Person(expectedId, expectedName); + // Then + String actualName = person.getName(); + Long actualId = person.getId(); + + Assert.assertEquals(expectedId, actualId); + Assert.assertEquals(expectedName, actualName); + + } + + @Test + public void testSetName() { + // Given + String expectedName = "SomeName"; + Person person = new Person(null,null); + + // When + person.setName(expectedName); + String actual = person.getName(); + + // Then + Assert.assertEquals(expectedName, actual); } } From 8a3ca4a9b0811b95c9406956fdca704ddc7a58dd Mon Sep 17 00:00:00 2001 From: razeroual <47251928+razeroual@users.noreply.github.com> Date: Tue, 21 Jul 2020 12:01:00 -0400 Subject: [PATCH 04/10] add Learner Interface --- src/main/java/com/github/curriculeon/Learner.java | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/main/java/com/github/curriculeon/Learner.java 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..4cd99c7 --- /dev/null +++ b/src/main/java/com/github/curriculeon/Learner.java @@ -0,0 +1,6 @@ +package com.github.curriculeon; + +public interface Learner { + public void learn(double numberOfHours); + public Double getTotalStudyTime(); +} From ac9731a509a99c68cc538fd62b8e38da083d9e05 Mon Sep 17 00:00:00 2001 From: razeroual <47251928+razeroual@users.noreply.github.com> Date: Tue, 21 Jul 2020 12:07:48 -0400 Subject: [PATCH 05/10] create a student class --- .../java/com/github/curriculeon/Student.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/com/github/curriculeon/Student.java 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..a267b47 --- /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, Double totalStudyTime) { + super(id, name); + this.totalStudyTime = totalStudyTime; + } + + @Override + public void learn(double numberOfHours) { + this.totalStudyTime = this.totalStudyTime + numberOfHours; + } + + @Override + public Double getTotalStudyTime() { + return this.totalStudyTime; + } +} From f22df504f5214e8c9725fc66d8687e8e5047487f Mon Sep 17 00:00:00 2001 From: razeroual <47251928+razeroual@users.noreply.github.com> Date: Tue, 21 Jul 2020 14:27:41 -0400 Subject: [PATCH 06/10] Create TestStudent class --- .../java/com/github/curriculeon/Student.java | 2 +- .../com/github/curriculeon/TestStudent.java | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/github/curriculeon/TestStudent.java diff --git a/src/main/java/com/github/curriculeon/Student.java b/src/main/java/com/github/curriculeon/Student.java index a267b47..5be4314 100644 --- a/src/main/java/com/github/curriculeon/Student.java +++ b/src/main/java/com/github/curriculeon/Student.java @@ -10,7 +10,7 @@ public Student(Long id, String name, Double totalStudyTime) { @Override public void learn(double numberOfHours) { - this.totalStudyTime = this.totalStudyTime + numberOfHours; + this.totalStudyTime += numberOfHours; } @Override 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..7d9c757 --- /dev/null +++ b/src/test/java/com/github/curriculeon/TestStudent.java @@ -0,0 +1,44 @@ +package com.github.curriculeon; + + +import org.junit.Assert; +import org.junit.Test; + +public class TestStudent { + @Test + public void testImplementation() { + //Given + Student student = new Student(0L, "some Name", 1.1); + + // When + boolean assertion = student instanceof Learner; + + // Then + Assert.assertTrue(assertion); + } + + @Test + public void testInheritance() { + //Given + Student student = new Student(0L, "some Name", 1.1); + + // When + boolean assertion = student instanceof Person; + + // Then + Assert.assertTrue(assertion); + } + @Test + + public void testLearn() { + //Given + Student student = new Student(0L, "some Name", 1.1); + + // When + student.learn(2); + double actualHours = student.getTotalStudyTime(); + + // Then + Assert.assertEquals(3.1, actualHours, 0.001); + } +} From fb4c867eae0344af55dee542c3e542ea16a16068 Mon Sep 17 00:00:00 2001 From: razeroual <47251928+razeroual@users.noreply.github.com> Date: Tue, 21 Jul 2020 15:00:02 -0400 Subject: [PATCH 07/10] Create Instructor class --- .../com/github/curriculeon/Instructor.java | 21 ++++++++ .../java/com/github/curriculeon/Teacher.java | 8 +++ .../github/curriculeon/TestInstructor.java | 49 +++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 src/main/java/com/github/curriculeon/Instructor.java create mode 100644 src/main/java/com/github/curriculeon/Teacher.java create mode 100644 src/test/java/com/github/curriculeon/TestInstructor.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..810ebaf --- /dev/null +++ b/src/main/java/com/github/curriculeon/Instructor.java @@ -0,0 +1,21 @@ +package com.github.curriculeon; + +public class Instructor extends Person implements Teacher { + + public Instructor(Long id, String name) { + super(id, name); + } + + @Override + public void tech(Learner learner, double numberOfHours) { + learner.learn(numberOfHours); + } + + @Override + public void lecture(Learner[] learners, double numberOfHours) { + for (Learner element : learners) { + element.learn(numberOfHours / learners.length); + } + } + +} 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..b7329fd --- /dev/null +++ b/src/main/java/com/github/curriculeon/Teacher.java @@ -0,0 +1,8 @@ +package com.github.curriculeon; + +public interface Teacher { + + void tech(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..708d639 --- /dev/null +++ b/src/test/java/com/github/curriculeon/TestInstructor.java @@ -0,0 +1,49 @@ +package com.github.curriculeon; + + +import org.junit.Assert; +import org.junit.Test; + +public class TestInstructor { + @Test + public void testImplementation() { + //Given + + Instructor instructor = new Instructor(0L, "some Name"); + + // When + boolean assertion = instructor instanceof Teacher; + + // Then + Assert.assertTrue(assertion); + + } + + @Test + public void testInheritance () { + //Given + + Instructor instructor = new Instructor(0L, "some Name"); + + // When + boolean assertion = instructor instanceof Person; + + // Then + Assert.assertTrue(assertion); + + } + + @Test + public void testInheritance () { + //Given + + Instructor instructor = new Instructor(0L, "some Name"); + + // When + boolean assertion = instructor instanceof Person; + + // Then + Assert.assertTrue(assertion); + + } +} From 17c110f2a6f3288206a61817a0811a1fe33593d5 Mon Sep 17 00:00:00 2001 From: razeroual <47251928+razeroual@users.noreply.github.com> Date: Mon, 27 Jul 2020 00:23:38 -0400 Subject: [PATCH 08/10] add TestInstructor --- .../com/github/curriculeon/Instructor.java | 6 +-- .../java/com/github/curriculeon/Learner.java | 2 +- .../java/com/github/curriculeon/Student.java | 7 ++-- .../java/com/github/curriculeon/Teacher.java | 4 +- .../github/curriculeon/TestInstructor.java | 39 ++++++++++++++++--- .../com/github/curriculeon/TestStudent.java | 14 +++---- 6 files changed, 50 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/github/curriculeon/Instructor.java b/src/main/java/com/github/curriculeon/Instructor.java index 810ebaf..e8b6307 100644 --- a/src/main/java/com/github/curriculeon/Instructor.java +++ b/src/main/java/com/github/curriculeon/Instructor.java @@ -7,14 +7,14 @@ public Instructor(Long id, String name) { } @Override - public void tech(Learner learner, double numberOfHours) { + public void teach(Learner learner, Double numberOfHours) { learner.learn(numberOfHours); } @Override - public void lecture(Learner[] learners, double numberOfHours) { + public void lecture(Learner[] learners, Double numberOfHours) { for (Learner element : learners) { - element.learn(numberOfHours / learners.length); + teach(element, (numberOfHours / learners.length)); } } diff --git a/src/main/java/com/github/curriculeon/Learner.java b/src/main/java/com/github/curriculeon/Learner.java index 4cd99c7..c68a4c2 100644 --- a/src/main/java/com/github/curriculeon/Learner.java +++ b/src/main/java/com/github/curriculeon/Learner.java @@ -1,6 +1,6 @@ package com.github.curriculeon; public interface Learner { - public void learn(double numberOfHours); + public void learn(Double numberOfHours); public Double getTotalStudyTime(); } diff --git a/src/main/java/com/github/curriculeon/Student.java b/src/main/java/com/github/curriculeon/Student.java index 5be4314..3d68eea 100644 --- a/src/main/java/com/github/curriculeon/Student.java +++ b/src/main/java/com/github/curriculeon/Student.java @@ -1,15 +1,14 @@ package com.github.curriculeon; public class Student extends Person implements Learner { - private Double totalStudyTime; + private Double totalStudyTime = 0.0; - public Student(Long id, String name, Double totalStudyTime) { + public Student(Long id, String name) { super(id, name); - this.totalStudyTime = totalStudyTime; } @Override - public void learn(double numberOfHours) { + public void learn(Double numberOfHours) { this.totalStudyTime += numberOfHours; } diff --git a/src/main/java/com/github/curriculeon/Teacher.java b/src/main/java/com/github/curriculeon/Teacher.java index b7329fd..0fdb3af 100644 --- a/src/main/java/com/github/curriculeon/Teacher.java +++ b/src/main/java/com/github/curriculeon/Teacher.java @@ -2,7 +2,7 @@ public interface Teacher { - void tech(Learner learner, double numberOfHours); - void lecture(Learner[] learners, double numberOfHours); + 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 index 708d639..da03894 100644 --- a/src/test/java/com/github/curriculeon/TestInstructor.java +++ b/src/test/java/com/github/curriculeon/TestInstructor.java @@ -20,7 +20,7 @@ public void testImplementation() { } @Test - public void testInheritance () { + public void testInheritance() { //Given Instructor instructor = new Instructor(0L, "some Name"); @@ -34,16 +34,45 @@ public void testInheritance () { } @Test - public void testInheritance () { + public void testTeach(){ //Given Instructor instructor = new Instructor(0L, "some Name"); + Student student = new Student(0L, "some student"); + Double numberOfHours = 5.5; + Double expected = student.getTotalStudyTime()+ numberOfHours; // When - boolean assertion = instructor instanceof Person; - + instructor.teach(student, numberOfHours); + Double actual = student.getTotalStudyTime(); // Then - Assert.assertTrue(assertion); + Assert.assertEquals(expected, actual, 0); + } + + @Test + public void testLecture (){ + //Given + + Instructor instructor = new Instructor(0L, "some Name"); + + Student[] students = { new Student(0L, "Chris"), + new Student(0L, "Chris"), + new Student(2L, "william")}; + + Double numberOfHours = 12.0; + + // When + instructor.lecture(students, numberOfHours); + + Double expected = numberOfHours/students.length; + for (int i = 0; i < students.length ; i++) { + Double actual = students[i].getTotalStudyTime(); + // Then + Assert.assertEquals(expected, actual, 0); + } + + } + } diff --git a/src/test/java/com/github/curriculeon/TestStudent.java b/src/test/java/com/github/curriculeon/TestStudent.java index 7d9c757..5d460dd 100644 --- a/src/test/java/com/github/curriculeon/TestStudent.java +++ b/src/test/java/com/github/curriculeon/TestStudent.java @@ -1,6 +1,5 @@ package com.github.curriculeon; - import org.junit.Assert; import org.junit.Test; @@ -8,7 +7,7 @@ public class TestStudent { @Test public void testImplementation() { //Given - Student student = new Student(0L, "some Name", 1.1); + Student student = new Student(0L, "some Name"); // When boolean assertion = student instanceof Learner; @@ -20,7 +19,7 @@ public void testImplementation() { @Test public void testInheritance() { //Given - Student student = new Student(0L, "some Name", 1.1); + Student student = new Student(0L, "some Name"); // When boolean assertion = student instanceof Person; @@ -28,17 +27,18 @@ public void testInheritance() { // Then Assert.assertTrue(assertion); } - @Test + @Test public void testLearn() { //Given - Student student = new Student(0L, "some Name", 1.1); + Student student = new Student(0L, "some Name"); // When - student.learn(2); + student.learn(2.0); + student.learn(2.0); double actualHours = student.getTotalStudyTime(); // Then - Assert.assertEquals(3.1, actualHours, 0.001); + Assert.assertEquals(4.0, actualHours, 0.001); } } From bb700412cc27c654507f595552f129b9cc0a3f68 Mon Sep 17 00:00:00 2001 From: razeroual <47251928+razeroual@users.noreply.github.com> Date: Mon, 17 Aug 2020 01:30:49 -0400 Subject: [PATCH 09/10] add classes --- .../com/github/curriculeon/Classroom.java | 18 ++++++ .../com/github/curriculeon/Instructors.java | 23 +++++++ .../java/com/github/curriculeon/People.java | 64 +++++++++++++++++++ .../java/com/github/curriculeon/Student.java | 2 +- .../java/com/github/curriculeon/Students.java | 23 +++++++ .../com/github/curriculeon/TestClassroom.java | 6 ++ .../github/curriculeon/TestInstructor.java | 2 +- .../github/curriculeon/TestInstructors.java | 24 +++++++ .../com/github/curriculeon/TestPeople.java | 50 +++++++++++++++ .../com/github/curriculeon/TestStudents.java | 30 +++++++++ 10 files changed, 240 insertions(+), 2 deletions(-) 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/People.java create mode 100644 src/main/java/com/github/curriculeon/Students.java create mode 100644 src/test/java/com/github/curriculeon/TestClassroom.java create mode 100644 src/test/java/com/github/curriculeon/TestInstructors.java create mode 100644 src/test/java/com/github/curriculeon/TestPeople.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..16ad5c3 --- /dev/null +++ b/src/main/java/com/github/curriculeon/Classroom.java @@ -0,0 +1,18 @@ +package com.github.curriculeon; + +public enum Classroom { + INSTANCE; + private Students students = Students.getInstance(); + private Instructors instructors = Instructors.getInstance(); + + public void hostLecture (Teacher teacher, double numberOfHours{ + teacher.lecture((Learner[]) students.toArray(), numberOfHours); + } + + public void hostLecture (long id, Double numberOfHours){ + Teacher instructor = instructors.findById(id); + instructor.lecture((Learner[]) students.toArray(), numberOfHours); + } + + +} 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..e601482 --- /dev/null +++ b/src/main/java/com/github/curriculeon/Instructors.java @@ -0,0 +1,23 @@ +package com.github.curriculeon; + +import java.lang.reflect.Constructor; + +public class Instructors extends People { + + private static final Instructors instance = new Instructors(); + + public Instructors() { + this.add(new Instructor(0L, "Leon Hunter")); + this.add(new Instructor(1L, "Haseeb Muhammad")); + } + + @Override + public Instructor[] toArray() { + return personList.toArray(new Instructor[count()]); + } + + 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 new file mode 100644 index 0000000..816efe8 --- /dev/null +++ b/src/main/java/com/github/curriculeon/People.java @@ -0,0 +1,64 @@ +package com.github.curriculeon; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class People implements Iterable { + List personList; + + public People() { + this(new ArrayList<>()); + } + + public People(List personList) { + this.personList = personList; + } + + public void add(SomePerson person){ + personList.add(person); + } + + public SomePerson findById(long id){ + for (SomePerson person: personList) { + if(person.getId().equals(id)){ + return person; + } + } + return null; + } + + public boolean contains(SomePerson person){ + return this.personList.contains(person); + } + + public void remove(SomePerson person){ + this.personList.remove(person); + } + + public void remove(long id){ + for (Person person: personList) { + if(person.getId().equals(id)){ + this.personList.remove(person); + } + } + } + + public void removeAll(){ + this.personList.clear(); + } + + public int count(){ + return this.personList.size(); + } + + public Person[] toArray(){ //return People or Person ?? + return this.personList.toArray(new Person[personList.size()]); + } + + + @Override + public Iterator iterator() { + return personList.iterator(); + } +} diff --git a/src/main/java/com/github/curriculeon/Student.java b/src/main/java/com/github/curriculeon/Student.java index 3d68eea..28b4c6e 100644 --- a/src/main/java/com/github/curriculeon/Student.java +++ b/src/main/java/com/github/curriculeon/Student.java @@ -1,7 +1,7 @@ package com.github.curriculeon; public class Student extends Person implements Learner { - private Double totalStudyTime = 0.0; + private double totalStudyTime = 0.0; public Student(Long id, String name) { super(id, name); 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..90a7e59 --- /dev/null +++ b/src/main/java/com/github/curriculeon/Students.java @@ -0,0 +1,23 @@ +package com.github.curriculeon; + +public class Students extends People { + private static final Students instance = new Students(); + + private Students(){ + super(); + this.add(new Student(0L, "Chris")); + this.add(new Student(1L, "William")); + this.add(new Student(2L, "Adam")); + } + + @Override + public Person[] toArray() { + return super.toArray(); + + // return personList.toArray(new Student[count()]); + } + + 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..75590f8 --- /dev/null +++ b/src/test/java/com/github/curriculeon/TestClassroom.java @@ -0,0 +1,6 @@ +package com.github.curriculeon; + +public class TestClassroom { + + +} diff --git a/src/test/java/com/github/curriculeon/TestInstructor.java b/src/test/java/com/github/curriculeon/TestInstructor.java index da03894..7d28b38 100644 --- a/src/test/java/com/github/curriculeon/TestInstructor.java +++ b/src/test/java/com/github/curriculeon/TestInstructor.java @@ -56,7 +56,7 @@ public void testLecture (){ Instructor instructor = new Instructor(0L, "some Name"); Student[] students = { new Student(0L, "Chris"), - new Student(0L, "Chris"), + new Student(0L, "Adam"), new Student(2L, "william")}; Double numberOfHours = 12.0; 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..c7bc736 --- /dev/null +++ b/src/test/java/com/github/curriculeon/TestInstructors.java @@ -0,0 +1,24 @@ +package com.github.curriculeon; + +import org.junit.Assert; +import org.junit.Test; + +import java.lang.reflect.Constructor; +import java.util.Arrays; +import java.util.List; + +public class TestInstructors { + @Test + public void test() { + + Instructors instructors = Instructors.getInstance(); + String[] instructorsArray = {"Leon Hunter", "Haseeb Muhammad"}; + List studentNameList = Arrays.asList(instructorsArray); + + Instructor[] InstructorArray = instructors.toArray(); + for (Instructor instructor : InstructorArray) { + boolean hasPersonWithName = studentNameList.contains((instructor.getName())); + Assert.assertTrue(hasPersonWithName); + } + } +} 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..736b71e --- /dev/null +++ b/src/test/java/com/github/curriculeon/TestPeople.java @@ -0,0 +1,50 @@ +package com.github.curriculeon; + + +import org.junit.Assert; +import org.junit.Test; + +public class TestPeople { + @Test + public void testAdd() { + //Given + Person person = new Person(null, null); + People people = new People(); + // When + Assert.assertFalse(people.contains(person)); + people.add(person); + + // Then + Assert.assertTrue(people.contains(person)); + + } + + @Test + public void testRemove() { + //Given + Person person1 = new Person(1L, null); + People people1 = new People(); + + // When + people1.add(person1); + Assert.assertTrue(people1.contains(person1)); + people1.remove(person1); + // Then + Assert.assertFalse(people1.contains(person1)); + + } + + @Test + public void testFindById() { + //Given + Person person1 = new Person(1L, null); + People people1 = new People(); + people1.removeAll(); + // When + people1.add(person1); + Person actualPerson = people1.findById(1L); + // Then + Assert.assertEquals(person1,actualPerson); + + } +} \ No newline at end of file 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..f1744e5 --- /dev/null +++ b/src/test/java/com/github/curriculeon/TestStudents.java @@ -0,0 +1,30 @@ + +package com.github.curriculeon; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + + +public class TestStudents { + + @Test + public void test() { + Students students = Students.getInstance(); + String[] studentNameArray = {"Chris", "William", "Adam"}; + List studentNameList = Arrays.asList(studentNameArray); + + Person[] studentArray = students.toArray(); + for (Person person: studentArray) { + boolean hasPersonWithName = studentNameList.contains((person.getName())); + Assert.assertTrue(hasPersonWithName); + } + + } + + + +} From 7a31e7574caae393a7aaf9cbb9473a3e7bec6524 Mon Sep 17 00:00:00 2001 From: razeroual <47251928+razeroual@users.noreply.github.com> Date: Mon, 17 Aug 2020 23:42:16 -0400 Subject: [PATCH 10/10] done --- .../com/github/curriculeon/Classroom.java | 18 +++++++++--- .../java/com/github/curriculeon/Educator.java | 28 +++++++++++++++++++ .../java/com/github/curriculeon/People.java | 10 ++++--- .../java/com/github/curriculeon/Students.java | 10 +++---- .../com/github/curriculeon/TestClassroom.java | 28 +++++++++++++++++++ .../com/github/curriculeon/TestPeople.java | 6 ++-- 6 files changed, 84 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/github/curriculeon/Educator.java diff --git a/src/main/java/com/github/curriculeon/Classroom.java b/src/main/java/com/github/curriculeon/Classroom.java index 16ad5c3..2d112c8 100644 --- a/src/main/java/com/github/curriculeon/Classroom.java +++ b/src/main/java/com/github/curriculeon/Classroom.java @@ -1,18 +1,28 @@ package com.github.curriculeon; +import java.util.HashMap; +import java.util.Map; + public enum Classroom { INSTANCE; private Students students = Students.getInstance(); private Instructors instructors = Instructors.getInstance(); - public void hostLecture (Teacher teacher, double numberOfHours{ - teacher.lecture((Learner[]) students.toArray(), numberOfHours); + public void hostLecture (Teacher teacher, Double numberOfHours){ + teacher.lecture(students.toArray(), numberOfHours); } public void hostLecture (long id, Double numberOfHours){ Teacher instructor = instructors.findById(id); - instructor.lecture((Learner[]) students.toArray(), numberOfHours); + instructor.lecture(students.toArray(), numberOfHours); + } + public Map getStudyMap(){ + Map result = new HashMap<>(); + for (Student student: students.toArray()) { + Double studyTime = student.getTotalStudyTime(); + result.put(student,studyTime); + } + return result; } - } 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..102b1ea --- /dev/null +++ b/src/main/java/com/github/curriculeon/Educator.java @@ -0,0 +1,28 @@ +package com.github.curriculeon; + +public enum Educator implements Teacher { + LEON, + HASEEB; + + private Double hoursWorked; + private final Instructor instructor; + + Educator() { + long id = this.ordinal(); + String name = this.name(); + this.instructor = new Instructor(id, name); + Instructors.getInstance().add(instructor); + } + + @Override + public void teach(Learner learner, Double numberOfHours) { + instructor.teach(learner, numberOfHours); + hoursWorked = numberOfHours; + } + + @Override + public void lecture(Learner[] learners, Double numberOfHours) { + instructor.lecture(learners, numberOfHours); + hoursWorked += numberOfHours; + } +} diff --git a/src/main/java/com/github/curriculeon/People.java b/src/main/java/com/github/curriculeon/People.java index 816efe8..2d4ec37 100644 --- a/src/main/java/com/github/curriculeon/People.java +++ b/src/main/java/com/github/curriculeon/People.java @@ -4,7 +4,7 @@ import java.util.Iterator; import java.util.List; -public class People implements Iterable { +public abstract class People implements Iterable { List personList; public People() { @@ -52,10 +52,12 @@ public int count(){ return this.personList.size(); } - public Person[] toArray(){ //return People or Person ?? - return this.personList.toArray(new Person[personList.size()]); - } + abstract public SomePerson[] toArray(); + +// public Person[] toArray(){ //return People or Person ?? +// return this.personList.toArray(new Person[personList.size()]); +// } @Override public Iterator iterator() { diff --git a/src/main/java/com/github/curriculeon/Students.java b/src/main/java/com/github/curriculeon/Students.java index 90a7e59..3fe0cfa 100644 --- a/src/main/java/com/github/curriculeon/Students.java +++ b/src/main/java/com/github/curriculeon/Students.java @@ -1,6 +1,8 @@ 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 Students(){ @@ -11,10 +13,8 @@ private Students(){ } @Override - public Person[] toArray() { - return super.toArray(); - - // return personList.toArray(new Student[count()]); + public Student[] toArray() { + return personList.toArray(new Student[count()]); } public static Students getInstance(){ diff --git a/src/test/java/com/github/curriculeon/TestClassroom.java b/src/test/java/com/github/curriculeon/TestClassroom.java index 75590f8..3e3a6ba 100644 --- a/src/test/java/com/github/curriculeon/TestClassroom.java +++ b/src/test/java/com/github/curriculeon/TestClassroom.java @@ -1,6 +1,34 @@ package com.github.curriculeon; +import org.junit.Assert; +import org.junit.Test; + +import java.util.Map; +import java.util.Set; + public class TestClassroom { + @Test + public void testHostLecture() { + //given + Classroom classroom = Classroom.INSTANCE; + Teacher teacher = Instructors.getInstance().findById(0L); + Integer numberOfStudents = Students.getInstance().count(); + Double numberOfHoursToLecture = numberOfStudents.doubleValue(); + Double expectedNumberOfHoursLearned = numberOfHoursToLecture / numberOfStudents; + Map preStudyMap = classroom.getStudyMap(); + + //When + classroom.hostLecture(teacher, numberOfHoursToLecture); + Map postStudyMap = classroom.getStudyMap(); + Set keySet = postStudyMap.keySet(); + for (Student student : keySet) { + Double preStudyTime = preStudyMap.get(student); + Double expectedStudyTime = preStudyTime + expectedNumberOfHoursLearned; + Double actualStudyTime = postStudyMap.get(student); + // then + Assert.assertEquals(expectedStudyTime, actualStudyTime); + } + } } diff --git a/src/test/java/com/github/curriculeon/TestPeople.java b/src/test/java/com/github/curriculeon/TestPeople.java index 736b71e..e9523c6 100644 --- a/src/test/java/com/github/curriculeon/TestPeople.java +++ b/src/test/java/com/github/curriculeon/TestPeople.java @@ -9,7 +9,7 @@ public class TestPeople { public void testAdd() { //Given Person person = new Person(null, null); - People people = new People(); + People people = Instructors.getInstance(); // When Assert.assertFalse(people.contains(person)); people.add(person); @@ -23,7 +23,7 @@ public void testAdd() { public void testRemove() { //Given Person person1 = new Person(1L, null); - People people1 = new People(); + People people1 = Instructors.getInstance(); // When people1.add(person1); @@ -38,7 +38,7 @@ public void testRemove() { public void testFindById() { //Given Person person1 = new Person(1L, null); - People people1 = new People(); + People people1 = Instructors.getInstance(); people1.removeAll(); // When people1.add(person1);