From 16abbc71c7068992e760fcd8995659cd8e67717b Mon Sep 17 00:00:00 2001 From: Marcus Katalenas Date: Mon, 20 Jul 2020 11:34:41 -0400 Subject: [PATCH 01/10] Inital work of part 1 --- .../java/com/github/curriculeon/Person.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/com/github/curriculeon/Person.java b/src/main/java/com/github/curriculeon/Person.java index 3c8350b..6f5b330 100644 --- a/src/main/java/com/github/curriculeon/Person.java +++ b/src/main/java/com/github/curriculeon/Person.java @@ -1,5 +1,24 @@ package com.github.curriculeon; public class Person { + private final long id; + private String name; + + Person(long i, String s){ + id = i; + name = s; + } + + public long getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } } From a5bb44859fa1b03acecce55757784c9dfb98cb11 Mon Sep 17 00:00:00 2001 From: Marcus Katalenas Date: Mon, 20 Jul 2020 14:39:18 -0400 Subject: [PATCH 02/10] Created my first test case ever using maven and passed successfully --- .../java/com/github/curriculeon/TestPerson.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/github/curriculeon/TestPerson.java b/src/test/java/com/github/curriculeon/TestPerson.java index 6c523fe..e50110e 100644 --- a/src/test/java/com/github/curriculeon/TestPerson.java +++ b/src/test/java/com/github/curriculeon/TestPerson.java @@ -1,5 +1,20 @@ package com.github.curriculeon; - +import org.junit.Assert; +import org.junit.Test; public class TestPerson { + private void test(long expectedLong, String expectedString){ + Person person = new Person(expectedLong, expectedString); + + long actualLong = person.getId(); + String actualString = person.getName(); + + Assert.assertEquals(expectedLong, actualLong); + Assert.assertEquals(expectedString, actualString); + } + + @Test + public void test0(){ + test(1, "Marcus"); + } } From 7541ce40f60b6195d970fc808d8d266dda20c233 Mon Sep 17 00:00:00 2001 From: Marcus Katalenas Date: Mon, 20 Jul 2020 14:44:57 -0400 Subject: [PATCH 03/10] Finished the setName test --- .../java/com/github/curriculeon/Person.java | 4 ++++ .../com/github/curriculeon/TestPerson.java | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/curriculeon/Person.java b/src/main/java/com/github/curriculeon/Person.java index 6f5b330..99b54e9 100644 --- a/src/main/java/com/github/curriculeon/Person.java +++ b/src/main/java/com/github/curriculeon/Person.java @@ -4,6 +4,10 @@ public class Person { private final long id; private String name; + Person(){ + id = 0; + name = ""; + } Person(long i, String s){ id = i; name = s; diff --git a/src/test/java/com/github/curriculeon/TestPerson.java b/src/test/java/com/github/curriculeon/TestPerson.java index e50110e..35ecf35 100644 --- a/src/test/java/com/github/curriculeon/TestPerson.java +++ b/src/test/java/com/github/curriculeon/TestPerson.java @@ -3,7 +3,7 @@ import org.junit.Test; public class TestPerson { - private void test(long expectedLong, String expectedString){ + private void testConstructor(long expectedLong, String expectedString){ Person person = new Person(expectedLong, expectedString); long actualLong = person.getId(); @@ -13,8 +13,23 @@ private void test(long expectedLong, String expectedString){ Assert.assertEquals(expectedString, actualString); } + public void testSetName(String expectedString){ + Person person = new Person(); + + person.setName(expectedString); + String actualString = person.getName(); + + Assert.assertEquals(expectedString, actualString); + + } + @Test public void test0(){ - test(1, "Marcus"); + testConstructor(1, "Marcus"); + } + + @Test + public void test1(){ + testSetName("Marcus Katalenas"); } } From 93bfad4fb1b260a8bd182b7674f1aa50215a4842 Mon Sep 17 00:00:00 2001 From: Marcus Katalenas Date: Tue, 21 Jul 2020 09:14:56 -0400 Subject: [PATCH 04/10] Finished part 2 created the learner interface --- src/main/java/com/github/curriculeon/Learner.java | 6 ++++++ src/test/java/com/github/curriculeon/TestPerson.java | 5 +++++ 2 files changed, 11 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..a779667 --- /dev/null +++ b/src/main/java/com/github/curriculeon/Learner.java @@ -0,0 +1,6 @@ +package com.github.curriculeon; + +interface Learner { + void learn(double numberOfHours); + double getTotalStudyTime(); +} diff --git a/src/test/java/com/github/curriculeon/TestPerson.java b/src/test/java/com/github/curriculeon/TestPerson.java index 35ecf35..e6034c5 100644 --- a/src/test/java/com/github/curriculeon/TestPerson.java +++ b/src/test/java/com/github/curriculeon/TestPerson.java @@ -32,4 +32,9 @@ public void test0(){ public void test1(){ testSetName("Marcus Katalenas"); } + + @Test + public void test2(){ + testSetName(""); + } } From 374274730f15b1f85ca0e049c9e24e809553dcac Mon Sep 17 00:00:00 2001 From: Marcus Katalenas Date: Tue, 21 Jul 2020 09:46:39 -0400 Subject: [PATCH 05/10] Finished part 3 --- .../java/com/github/curriculeon/Learner.java | 4 +- .../java/com/github/curriculeon/Student.java | 21 +++++++ .../com/github/curriculeon/TestStudent.java | 55 +++++++++++++++++++ 3 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/github/curriculeon/Student.java create mode 100644 src/test/java/com/github/curriculeon/TestStudent.java diff --git a/src/main/java/com/github/curriculeon/Learner.java b/src/main/java/com/github/curriculeon/Learner.java index a779667..70a38dc 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; interface Learner { - void learn(double numberOfHours); - double getTotalStudyTime(); + void learn(Double numberOfHours); + Double getTotalStudyTime(); } 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..79f97a0 --- /dev/null +++ b/src/main/java/com/github/curriculeon/Student.java @@ -0,0 +1,21 @@ +package com.github.curriculeon; + +public class Student extends Person implements Learner { + private Double totalStudyTime = 0.0; + + public Student(){ + super(); + } + public Student(Double numOfHours){ + super(); + learn(numOfHours); + } + public void learn(Double numberOfHours) { + totalStudyTime += numberOfHours; + } + + + public Double getTotalStudyTime() { + return totalStudyTime; + } +} 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..dfa4eeb --- /dev/null +++ b/src/test/java/com/github/curriculeon/TestStudent.java @@ -0,0 +1,55 @@ +package com.github.curriculeon; +import org.junit.Assert; +import org.junit.Test; + +public class TestStudent { + + public void testImplementation(){ + //Given + + //Where + + //Then + Student studentOne = new Student(); + Assert.assertTrue(studentOne instanceof Learner); + + } + public void testInheritance(){ + //Given + + //Where + + //Then + Student studentTwo = new Student(); + Assert.assertTrue(studentTwo instanceof Person); + } + public void testLearn(Double expectedTimeToAdd){ + //Given + Student studentThree = new Student(4.5); + //Where + Double actualHours = studentThree.getTotalStudyTime() + expectedTimeToAdd; + //Then + studentThree.learn(expectedTimeToAdd); + Double newHours = studentThree.getTotalStudyTime(); + Assert.assertEquals(newHours, actualHours); + } + + @Test + public void test0(){ + testImplementation(); + } + + @Test + public void test1(){ + testInheritance(); + } + + @Test + public void test2(){ + testLearn(5.5); + } +} + + + + From 1e6fe38437eec7776c6efa916c38f103d59071e2 Mon Sep 17 00:00:00 2001 From: Marcus Katalenas Date: Tue, 21 Jul 2020 09:48:59 -0400 Subject: [PATCH 06/10] Finished Part 4.0 created a teacher interface --- src/main/java/com/github/curriculeon/Teacher.java | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/main/java/com/github/curriculeon/Teacher.java 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..2d9a34b --- /dev/null +++ b/src/main/java/com/github/curriculeon/Teacher.java @@ -0,0 +1,6 @@ +package com.github.curriculeon; + +public interface Teacher { + void teach(Learner learner, double numberOfHours); + void lecture(Learner[] learners, double numberOfHours); +} From 84a822a8b31c9745eb661824757e0cd06c7c5910 Mon Sep 17 00:00:00 2001 From: Marcus Katalenas Date: Tue, 21 Jul 2020 09:56:12 -0400 Subject: [PATCH 07/10] Finised part 5.1 created the Instructor class --- .../java/com/github/curriculeon/Instructor.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/main/java/com/github/curriculeon/Instructor.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..a5a4c21 --- /dev/null +++ b/src/main/java/com/github/curriculeon/Instructor.java @@ -0,0 +1,17 @@ +package com.github.curriculeon; + +public class Instructor extends Person implements Teacher { + + + public void teach(Learner learner, double numberOfHours) { + learner.learn(numberOfHours); + } + + + public void lecture(Learner[] learners, double numberOfHours) { + double numberOfHoursPerLearner = numberOfHours / learners.length; + for (Learner l: learners) { + l.learn(numberOfHoursPerLearner); + } + } +} From cbcd3d926f3ec6f9fc9e27b0fec9a1b72a1859a3 Mon Sep 17 00:00:00 2001 From: Marcus Katalenas Date: Tue, 21 Jul 2020 10:29:13 -0400 Subject: [PATCH 08/10] Test cases almost done for part 5 --- .../github/curriculeon/TestInstructor.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/test/java/com/github/curriculeon/TestInstructor.java 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..a262c45 --- /dev/null +++ b/src/test/java/com/github/curriculeon/TestInstructor.java @@ -0,0 +1,61 @@ +package com.github.curriculeon; +import org.junit.Assert; +import org.junit.Test; + +public class TestInstructor { + public void testImplementation(){ + //Given + Instructor instructorOne = new Instructor(); + //Where + + //Then + Assert.assertTrue(instructorOne instanceof Teacher); + } + public void testInheritance(){ + //Given + Instructor instructorTwo = new Instructor(); + //Where + + //Then + Assert.assertTrue(instructorTwo instanceof Person); + } + public void testTeach(Double hoursToAdd){ + //Given + Instructor instructorThree = new Instructor(); + Student studentOne = new Student(); + Double currentStudentHours = studentOne.getTotalStudyTime(); + + //Where + Double expectedStudentHours = currentStudentHours + hoursToAdd; + instructorThree.teach(studentOne, hoursToAdd); + Double actualStudentHours = studentOne.getTotalStudyTime(); + + //Then + Assert.assertEquals(actualStudentHours, expectedStudentHours); + } + public void testLecture(Double hours){ + //Given + + //Where + + //Then + } + + @Test + public void test0(){ + testImplementation(); + } + + @Test + public void test1(){ + testInheritance(); + } + @Test + public void test2(){ + testTeach(5.0); + } + @Test + public void test3(){ + + } +} From cdc258a439d55597efc24ec3c7e5a04c07f46dac Mon Sep 17 00:00:00 2001 From: Marcus Katalenas Date: Wed, 22 Jul 2020 10:10:52 -0400 Subject: [PATCH 09/10] Inital work for part 6 of the learner lab --- .../com/github/curriculeon/Instructor.java | 6 +-- .../java/com/github/curriculeon/People.java | 43 +++++++++++++++++++ .../java/com/github/curriculeon/Student.java | 4 ++ .../github/curriculeon/TestInstructor.java | 34 ++++++++++----- .../com/github/curriculeon/TestStudent.java | 17 ++++---- 5 files changed, 83 insertions(+), 21 deletions(-) create mode 100644 src/main/java/com/github/curriculeon/People.java diff --git a/src/main/java/com/github/curriculeon/Instructor.java b/src/main/java/com/github/curriculeon/Instructor.java index a5a4c21..11021fb 100644 --- a/src/main/java/com/github/curriculeon/Instructor.java +++ b/src/main/java/com/github/curriculeon/Instructor.java @@ -9,9 +9,9 @@ public void teach(Learner learner, double numberOfHours) { public void lecture(Learner[] learners, double numberOfHours) { - double numberOfHoursPerLearner = numberOfHours / learners.length; - for (Learner l: learners) { - l.learn(numberOfHoursPerLearner); + double numberOfHoursPerStudent = numberOfHours/learners.length; + for (int count = 0; count < learners.length; count++){ + learners[count].learn(numberOfHoursPerStudent); } } } 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..3cba357 --- /dev/null +++ b/src/main/java/com/github/curriculeon/People.java @@ -0,0 +1,43 @@ +package com.github.curriculeon; + +import java.util.Iterator; +import java.util.List; + +public class People implements Iterable { + private List personList; + + public void add(Person person){ + personList.add(person); + } + public Person findById(long id){ + if(personList.contains(id)){ + return null; + } + else{ + return null; + } + } + public boolean contains(Person person){ + return personList.contains(person); + } + public void remove(Person person){ + personList.remove(person); + } + public void remove(long id){ + personList.remove(id); + } + public void removeAll(){ + personList.clear(); + } + public Integer count(){ + return personList.size(); + } + public Person[] toArray(){ + return (Person[]) personList.toArray(); + } + + @Override + public Iterator iterator() { + return (Iterator) personList.iterator(); + } +} diff --git a/src/main/java/com/github/curriculeon/Student.java b/src/main/java/com/github/curriculeon/Student.java index 79f97a0..e2bda89 100644 --- a/src/main/java/com/github/curriculeon/Student.java +++ b/src/main/java/com/github/curriculeon/Student.java @@ -6,6 +6,10 @@ public class Student extends Person implements Learner { public Student(){ super(); } + public Student(Long id, String name){ + super(id, name); + } + public Student(Double numOfHours){ super(); learn(numOfHours); diff --git a/src/test/java/com/github/curriculeon/TestInstructor.java b/src/test/java/com/github/curriculeon/TestInstructor.java index a262c45..bcd8325 100644 --- a/src/test/java/com/github/curriculeon/TestInstructor.java +++ b/src/test/java/com/github/curriculeon/TestInstructor.java @@ -5,16 +5,17 @@ public class TestInstructor { public void testImplementation(){ //Given - Instructor instructorOne = new Instructor(); - //Where + Object instructorOne = new Instructor(); + + //When //Then Assert.assertTrue(instructorOne instanceof Teacher); } public void testInheritance(){ //Given - Instructor instructorTwo = new Instructor(); - //Where + Object instructorTwo = new Instructor(); + //When //Then Assert.assertTrue(instructorTwo instanceof Person); @@ -24,9 +25,9 @@ public void testTeach(Double hoursToAdd){ Instructor instructorThree = new Instructor(); Student studentOne = new Student(); Double currentStudentHours = studentOne.getTotalStudyTime(); - - //Where Double expectedStudentHours = currentStudentHours + hoursToAdd; + + //When instructorThree.teach(studentOne, hoursToAdd); Double actualStudentHours = studentOne.getTotalStudyTime(); @@ -35,10 +36,21 @@ public void testTeach(Double hoursToAdd){ } public void testLecture(Double hours){ //Given - - //Where - + Teacher instructorFour = new Instructor(); + Learner[] students = new Learner[]{ + new Student(0l, "Marcus"), + new Student(1L, "Luke"), + new Student(2L, "Zach") + }; + Double expectedHours = hours/students.length; + //When + instructorFour.lecture(students, hours); //Then + for(int i = 0; i < students.length; i++){ + Learner learner = students[i]; + Double actualHours = learner.getTotalStudyTime(); + Assert.assertEquals(actualHours,expectedHours); + } } @Test @@ -50,12 +62,14 @@ public void test0(){ public void test1(){ testInheritance(); } + @Test public void test2(){ testTeach(5.0); } + @Test public void test3(){ - + testLecture(5.0); } } diff --git a/src/test/java/com/github/curriculeon/TestStudent.java b/src/test/java/com/github/curriculeon/TestStudent.java index dfa4eeb..07edc03 100644 --- a/src/test/java/com/github/curriculeon/TestStudent.java +++ b/src/test/java/com/github/curriculeon/TestStudent.java @@ -6,22 +6,23 @@ public class TestStudent { public void testImplementation(){ //Given - - //Where - - //Then Student studentOne = new Student(); - Assert.assertTrue(studentOne instanceof Learner); + //When + Boolean result = studentOne instanceof Learner; + //Then + + Assert.assertTrue(result); } public void testInheritance(){ //Given + Student studentTwo = new Student(); //Where - + Boolean result = studentTwo instanceof Person; //Then - Student studentTwo = new Student(); - Assert.assertTrue(studentTwo instanceof Person); + + Assert.assertTrue(result); } public void testLearn(Double expectedTimeToAdd){ //Given From 4659c17d84f5ea64d3fa2c39486e528a23bd0c2b Mon Sep 17 00:00:00 2001 From: Marcus Katalenas Date: Wed, 22 Jul 2020 10:41:06 -0400 Subject: [PATCH 10/10] Created the Students singleton --- .../java/com/github/curriculeon/People.java | 2 +- .../java/com/github/curriculeon/Students.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/github/curriculeon/Students.java diff --git a/src/main/java/com/github/curriculeon/People.java b/src/main/java/com/github/curriculeon/People.java index 3cba357..02e5100 100644 --- a/src/main/java/com/github/curriculeon/People.java +++ b/src/main/java/com/github/curriculeon/People.java @@ -38,6 +38,6 @@ public Person[] toArray(){ @Override public Iterator iterator() { - return (Iterator) personList.iterator(); + return (Iterator) personList.iterator(); } } 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..2a023f7 --- /dev/null +++ b/src/main/java/com/github/curriculeon/Students.java @@ -0,0 +1,22 @@ +package com.github.curriculeon; + +public class Students { + final private static Students INSTANCE; + + private Students(){ + + } + + static{ + try{ + INSTANCE = new Students(); + } + catch(Exception e){ + throw new RuntimeException("Error in creating singleton instance"); + } + } + + public static Students getInsatnce() { + return INSTANCE; + } +}