From 35cbb970ba0307e6e4ee34aa82f7b57f0e31c991 Mon Sep 17 00:00:00 2001 From: David Frary Date: Mon, 20 Jul 2020 14:55:05 -0400 Subject: [PATCH 1/8] finished edits on 'Person.java' --- .../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..fcad821 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; + + public Person (long id, String name){ + this.id = id; + this.name = name; + } + + public long getId(){ + return id; + } + + public String getName(String name){ + return name; + } + + public void setName (String name){ + this.name = name; + } } From f7ef1c901ff93c5f62332a86f9e30cd7f91814e7 Mon Sep 17 00:00:00 2001 From: David Frary Date: Mon, 20 Jul 2020 15:48:37 -0400 Subject: [PATCH 2/8] finished edits on 'TestPerson.java' --- .../com/github/curriculeon/TestPerson.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/test/java/com/github/curriculeon/TestPerson.java b/src/test/java/com/github/curriculeon/TestPerson.java index 6c523fe..1f563d3 100644 --- a/src/test/java/com/github/curriculeon/TestPerson.java +++ b/src/test/java/com/github/curriculeon/TestPerson.java @@ -1,5 +1,24 @@ package com.github.curriculeon; public class TestPerson { + private void testConstructor(long expectedId, String expectedName) { + Person person = new Person(expectedId, expectedName); + Long actualId = person.getId(); + String actualName = person.getName(); + Assert.assertEquals(expectedId, actualId); + Assert.assertEquals(expectedName, actualName()); + + } + + private void testSetName() { + Person person = new Person(id:null, name: null); + String expected Name = "Some name"; + + person.setName(expectedName); + String actualName = person.getName(); + + Assert.assertEquals(expectedName, actualName()); + + } } From 934c7cb40f0cb714338a641f1df99c622a0cfb0e Mon Sep 17 00:00:00 2001 From: David Frary Date: Mon, 20 Jul 2020 16:30:48 -0400 Subject: [PATCH 3/8] finished edits on 'TestPerson.java' --- .../java/com/github/curriculeon/Person.java | 6 ++-- .../com/github/curriculeon/TestPerson.java | 34 +++++++++++++------ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/github/curriculeon/Person.java b/src/main/java/com/github/curriculeon/Person.java index fcad821..c347c12 100644 --- a/src/main/java/com/github/curriculeon/Person.java +++ b/src/main/java/com/github/curriculeon/Person.java @@ -10,11 +10,11 @@ public Person (long id, String name){ } public long getId(){ - return id; + return this.id; } - public String getName(String name){ - return name; + public String getName(){ + return this.name; } public void setName (String name){ diff --git a/src/test/java/com/github/curriculeon/TestPerson.java b/src/test/java/com/github/curriculeon/TestPerson.java index 1f563d3..2b6f157 100644 --- a/src/test/java/com/github/curriculeon/TestPerson.java +++ b/src/test/java/com/github/curriculeon/TestPerson.java @@ -1,24 +1,36 @@ package com.github.curriculeon; +import org.junit.Assert; +import org.junit.Test; + public class TestPerson { - private void testConstructor(long expectedId, String expectedName) { + public void testConstructor() { + // given + Long expectedId = 0L; + String expectedName = "Some name"; + + // when Person person = new Person(expectedId, expectedName); - Long actualId = person.getId(); String actualName = person.getName(); + Long actualId = person.getId(); - Assert.assertEquals(expectedId, actualId); - Assert.assertEquals(expectedName, actualName()); - + // then + Assert.assertEquals(expectedId,actualId); + Assert.assertEquals(expectedName,actualName); } - private void testSetName() { - Person person = new Person(id:null, name: null); - String expected Name = "Some name"; + @Test + public void testSetName() { + // given + Person person = new Person(-1,null); + String expectedName = "Some name"; + Assert.assertNotEquals(expectedName, person.getName()); + // when person.setName(expectedName); String actualName = person.getName(); - Assert.assertEquals(expectedName, actualName()); - + // then + Assert.assertEquals(expectedName,actualName); } -} +} \ No newline at end of file From 00e6c6ce405febc2d4cd21dc3590d04f2b2c05f5 Mon Sep 17 00:00:00 2001 From: David Frary Date: Tue, 21 Jul 2020 11:05:16 -0400 Subject: [PATCH 4/8] finished edits on 'Person.java' --- .../java/com/github/curriculeon/Learner.java | 6 ++++++ .../java/com/github/curriculeon/Person.java | 16 +++++++------- .../java/com/github/curriculeon/Student.java | 21 +++++++++++++++++++ 3 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/github/curriculeon/Learner.java create mode 100644 src/main/java/com/github/curriculeon/Student.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(); +} diff --git a/src/main/java/com/github/curriculeon/Person.java b/src/main/java/com/github/curriculeon/Person.java index c347c12..e2fffa4 100644 --- a/src/main/java/com/github/curriculeon/Person.java +++ b/src/main/java/com/github/curriculeon/Person.java @@ -1,24 +1,24 @@ package com.github.curriculeon; public class Person { - private final long id; + final long id; private String name; - public Person (long id, String name){ + Person(long id, String name) { this.id = id; this.name = name; } - public long getId(){ - return this.id; + public long getId() { + return id; } - public String getName(){ - return this.name; + public String getName() { + return name; } - public void setName (String name){ + public void setName(String name) { this.name = name; } -} +} \ No newline at end of file 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..d4ab46b --- /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 { + double totalStudyTime; + + Student(long id, String name) { + super(id, name); + } + + @Override + public void learn(double numberOfHours) { + this.totalStudyTime+=numberOfHours; + + } + + @Override + public Double getTotalStudyTime() { + return this.totalStudyTime; + } + +} From 6b924650e482c82802c0e4ec9d53c3d226a2dd63 Mon Sep 17 00:00:00 2001 From: David Frary Date: Tue, 21 Jul 2020 11:32:34 -0400 Subject: [PATCH 5/8] finished edits on 'TestStudent.java' --- .../com/github/curriculeon/TestStudent.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/test/java/com/github/curriculeon/TestStudent.java 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..d16ef56 --- /dev/null +++ b/src/test/java/com/github/curriculeon/TestStudent.java @@ -0,0 +1,31 @@ +package com.github.curriculeon; + +import org.junit.Assert; +import org.junit.Test; + +public class TestStudent { + + @Test + public void testImplementation() { + Student student = new Student(1, "Name"); + Assert.assertTrue(student instanceof Learner); + } + + @Test + public void testInheritance() { + Student student = new Student(1, "Name"); + Assert.assertTrue(student instanceof Person); + } + + @Test + public void testLearn() { + Student student = new Student(1, "Name"); + double expectedNumberOfHours = 2.5; + student.learn(expectedNumberOfHours); + double actualNumberOfHours = student.getTotalStudyTime(); + Assert.assertEquals(expectedNumberOfHours, actualNumberOfHours, 0.1); + + } + + +} \ No newline at end of file From 3acd452852ef02ca647047363518dd720586ba93 Mon Sep 17 00:00:00 2001 From: David Frary Date: Tue, 21 Jul 2020 11:55:08 -0400 Subject: [PATCH 6/8] finished edits on 'TestInstructor.java' --- .../com/github/curriculeon/Instructor.java | 20 ++++++ .../java/com/github/curriculeon/Teacher.java | 7 ++ .../github/curriculeon/TestInstructor.java | 70 +++++++++++++++++++ 3 files changed, 97 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..4eeaff6 --- /dev/null +++ b/src/main/java/com/github/curriculeon/Instructor.java @@ -0,0 +1,20 @@ +package com.github.curriculeon; + +public class Instructor extends Person implements Teacher { + 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 (Learner learner : learners){ + this.teach(learner,numberOfHoursPerLearner); + } + } +} \ No newline at end of file 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..f5d37cb --- /dev/null +++ b/src/main/java/com/github/curriculeon/Teacher.java @@ -0,0 +1,7 @@ +package com.github.curriculeon; + +public interface Teacher { + void teach(Learner learner, double numberOfHours); + void lecture(Learner[] learners, double numberOfHours); + +} \ No newline at end of file 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..2ee65a3 --- /dev/null +++ b/src/test/java/com/github/curriculeon/TestInstructor.java @@ -0,0 +1,70 @@ +package com.github.curriculeon; + +import org.junit.Assert; +import org.junit.Test; + +public class TestInstructor { + + @Test + public void testImplementation() { + //given + Object instructor = new Instructor(0,""); + //when + boolean output = instructor instanceof Teacher; + //then + Assert.assertTrue(output); + } + + @Test + public void testInheritance() { + // given + Object instructor = new Instructor(1234, ""); + + // when + Boolean output = instructor instanceof Person; + + // then + Assert.assertTrue(output); + } + + public void testTeach(Learner learner,Double expected, Double numOfHours){ + // When + Instructor instructor = new Instructor(1234, "Name"); + instructor.teach(learner,numOfHours); + + // Then + Double actual = learner.getTotalStudyTime(); + Assert.assertEquals(expected, actual); + } + + public void testLecture(Learner[] learners,Double expected, Double numOfHours){ + // When + Instructor instructor = new Instructor(1234, "Name"); + instructor.lecture(learners,numOfHours); + + // Then + Double actual = learners[0].getTotalStudyTime(); + Assert.assertEquals(expected, actual); + } + + + @Test + public void test0(){ + Student student = new Student(1234, ""); + testTeach(student,5.0,5.0); + } + + @Test + public void test1(){ + Student student = new Student(1234, ""); + Student student2 = new Student(1234, ""); + Student student3 = new Student(1234, ""); + Learner[] students = new Learner[3]; + students[0] = student; + students[1] = student2; + students[2] = student3; + testLecture(students,3.0,9.0); + + } + +} \ No newline at end of file From 3f0cafff36cf436fcc29cc2b9329f837c36c445d Mon Sep 17 00:00:00 2001 From: David Frary Date: Tue, 21 Jul 2020 11:58:36 -0400 Subject: [PATCH 7/8] finished edits on 'TestInstructor.java' --- .../com/github/curriculeon/TestInstructor.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/github/curriculeon/TestInstructor.java b/src/test/java/com/github/curriculeon/TestInstructor.java index 2ee65a3..1d518bc 100644 --- a/src/test/java/com/github/curriculeon/TestInstructor.java +++ b/src/test/java/com/github/curriculeon/TestInstructor.java @@ -18,7 +18,7 @@ public void testImplementation() { @Test public void testInheritance() { // given - Object instructor = new Instructor(1234, ""); + Object instructor = new Instructor(1, ""); // when Boolean output = instructor instanceof Person; @@ -29,7 +29,7 @@ public void testInheritance() { public void testTeach(Learner learner,Double expected, Double numOfHours){ // When - Instructor instructor = new Instructor(1234, "Name"); + Instructor instructor = new Instructor(1, "Name"); instructor.teach(learner,numOfHours); // Then @@ -39,7 +39,7 @@ public void testTeach(Learner learner,Double expected, Double numOfHours){ public void testLecture(Learner[] learners,Double expected, Double numOfHours){ // When - Instructor instructor = new Instructor(1234, "Name"); + Instructor instructor = new Instructor(1, "Name"); instructor.lecture(learners,numOfHours); // Then @@ -50,15 +50,15 @@ public void testLecture(Learner[] learners,Double expected, Double numOfHours){ @Test public void test0(){ - Student student = new Student(1234, ""); + Student student = new Student(1, ""); testTeach(student,5.0,5.0); } @Test public void test1(){ - Student student = new Student(1234, ""); - Student student2 = new Student(1234, ""); - Student student3 = new Student(1234, ""); + Student student = new Student(1, ""); + Student student2 = new Student(1, ""); + Student student3 = new Student(1, ""); Learner[] students = new Learner[3]; students[0] = student; students[1] = student2; From 79d0a7bf11c9df5a9748d02360d1c41a88cc9511 Mon Sep 17 00:00:00 2001 From: David Frary Date: Sat, 25 Jul 2020 19:42:50 -0400 Subject: [PATCH 8/8] finished edits on 'TestPeople.java' --- .../java/com/github/curriculeon/People.java | 54 +++++++++++++ .../com/github/curriculeon/TestPeople.java | 76 +++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 src/main/java/com/github/curriculeon/People.java create mode 100644 src/test/java/com/github/curriculeon/TestPeople.java 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..fd96401 --- /dev/null +++ b/src/main/java/com/github/curriculeon/People.java @@ -0,0 +1,54 @@ +package com.github.curriculeon; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.lang.Iterable; + +public class People implements Iterable { + + List personList = new ArrayList<>(); + + public People() { + } + + public void add(Person person) { + personList.add(person); + } + + public Person findById(long id) { + for(Person person: personList) { + if(person.getId() == id) { + return person; + } + } + return null; + } + + public Boolean contains(Person person) { + return personList.contains(person); + } + + public void remove(Person person) { + personList.remove(person); + } + + public void removeAll() { + personList.clear(); + } + + public int count() { + return personList.size(); + } + + public void toArray() { + personList.toArray(); + } + + @Override + public Iterator iterator() { + return personList.listIterator(); + } + +} \ No newline at end of file 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..20b0244 --- /dev/null +++ b/src/test/java/com/github/curriculeon/TestPeople.java @@ -0,0 +1,76 @@ +package com.github.curriculeon; + +import org.junit.Assert; +import org.junit.Test; + +public class TestPeople{ + + @Test + public void testAdd() { + //given + Person expectedPerson1 = new Person(1111L, "John Doe"); + Person expectedPerson2 = new Person(2222L, "Jane Doe"); + Person expectedPerson3 = new Person(3333L, "Dennis Doe"); + + //when + People personList = new People(); + personList.add(expectedPerson1); + personList.add(expectedPerson2); + personList.add(expectedPerson3); + + //then + Assert.assertTrue(personList.contains(expectedPerson1)); + Assert.assertTrue(personList.contains(expectedPerson2)); + Assert.assertTrue(personList.contains(expectedPerson3)); + } + + @Test + public void testRemove() { + //given + Person Person1 = new Person(1111L, "John Doe"); + Person Person2 = new Person(2222L, "Jane Doe"); + Person Person3 = new Person(3333L, "Dennis Doe"); + + People personList = new People(); + personList.add(Person1); + personList.add(Person2); + personList.add(Person3); + + Assert.assertTrue(personList.contains(Person1)); + Assert.assertTrue(personList.contains(Person2)); + Assert.assertTrue(personList.contains(Person3)); + + //when + personList.remove(Person1); + personList.remove(Person2); + personList.remove(Person3); + + //then + Assert.assertFalse(personList.contains(Person1)); + Assert.assertFalse(personList.contains(Person2)); + Assert.assertFalse(personList.contains(Person3)); + } + + @Test + public void testFindById () { + //given + Person expectedPerson1 = new Person(1111L, "John Doe"); + Person expectedPerson2 = new Person(2222L, "Jane Doe"); + Person expectedPerson3 = new Person(3333L, "Dennis Doe"); + + People personList = new People(); + personList.add(expectedPerson1); + personList.add(expectedPerson2); + personList.add(expectedPerson3); + + //when + Person actualPerson1 = personList.findById(1111L); + Person actualPerson2 = personList.findById(2222L); + Person actualPerson3 = personList.findById(3333L); + + //then + Assert.assertEquals(expectedPerson1, actualPerson1); + Assert.assertEquals(expectedPerson2, actualPerson2); + Assert.assertEquals(expectedPerson3, actualPerson3); + } +}