From 579342244f21cd0153ad2e1d94605b810607f497 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 20 Jul 2020 13:04:29 -0400 Subject: [PATCH 1/7] Person class created; need to make TestPerson --- .../java/com/github/curriculeon/Person.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/com/github/curriculeon/Person.java b/src/main/java/com/github/curriculeon/Person.java index 3c8350b..6610c45 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 { + 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 75efddb12c64911dded83698474c9411950f3a17 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 20 Jul 2020 16:13:03 -0400 Subject: [PATCH 2/7] Completed Part 1 --- .../java/com/github/curriculeon/Person.java | 12 +++--- .../com/github/curriculeon/TestPerson.java | 42 ++++++++++++++++++- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/github/curriculeon/Person.java b/src/main/java/com/github/curriculeon/Person.java index 6610c45..3032515 100644 --- a/src/main/java/com/github/curriculeon/Person.java +++ b/src/main/java/com/github/curriculeon/Person.java @@ -1,19 +1,19 @@ package com.github.curriculeon; public class Person { - private final long id; + private final Long id; private String name; - - public Person (long id, String name) { - this.id = id; + + public Person (Long id, String name) { + this.id=id; this.name = name; } - public long getId() { + public Long getId() { return id; } - public String getName(String name) { + public String getName() { return name; } diff --git a/src/test/java/com/github/curriculeon/TestPerson.java b/src/test/java/com/github/curriculeon/TestPerson.java index 6c523fe..381be98 100644 --- a/src/test/java/com/github/curriculeon/TestPerson.java +++ b/src/test/java/com/github/curriculeon/TestPerson.java @@ -1,5 +1,45 @@ package com.github.curriculeon; +import org.junit.Assert; +import org.junit.Test; + +import java.time.LocalDate; +import java.time.Period; +import java.time.ZoneId; +import java.util.Date; + +/** + * Created by leon on 7/15/2020. + */ public class TestPerson { + @Test + public void testConstructor() { + //given + Long expectedId = 0L; + String expectedName = "Some Name"; + + // When + Person person = new Person(expectedId, expectedName); + + // Then + Long actualId = person.getId(); + String actualName = person.getName(); + + Assert.assertEquals(expectedId, actualId); + Assert.assertEquals(expectedName, actualName); + } + @Test + public void testSetName() { + // given + Person person = new Person(null, null); + String expectedName = "Some Name"; + Assert.assertNotEquals(expectedName, person.getName()); + + // when + person.setName(expectedName); + String actualName = person.getName(); -} + //then + Assert.assertEquals(expectedName, actualName); + } +} \ No newline at end of file From a1a35eae258f4bd76f7f0b2f7a04fd293d178d24 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 26 Jul 2020 18:29:31 -0400 Subject: [PATCH 3/7] done through 5 --- .../com/github/curriculeon/Instructor.java | 23 ++++++ .../java/com/github/curriculeon/Learner.java | 7 ++ .../java/com/github/curriculeon/Person.java | 8 +- .../java/com/github/curriculeon/Student.java | 21 ++++++ .../java/com/github/curriculeon/Teacher.java | 9 +++ .../github/curriculeon/TestInstructor.java | 74 +++++++++++++++++++ .../com/github/curriculeon/TestStudent.java | 56 ++++++++++++++ 7 files changed, 197 insertions(+), 1 deletion(-) 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/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/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..59b5289 --- /dev/null +++ b/src/main/java/com/github/curriculeon/Instructor.java @@ -0,0 +1,23 @@ +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..428e02e --- /dev/null +++ b/src/main/java/com/github/curriculeon/Learner.java @@ -0,0 +1,7 @@ +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 3032515..09ec0ec 100644 --- a/src/main/java/com/github/curriculeon/Person.java +++ b/src/main/java/com/github/curriculeon/Person.java @@ -3,13 +3,18 @@ public class Person { private final Long id; private String name; - + + public Person() { + this.id = null; + } + public Person (Long id, String name) { this.id=id; this.name = name; } public Long getId() { + return id; } @@ -18,6 +23,7 @@ public String getName() { } 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..26f1d68 --- /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 = 2.0; + + public Student(Long id, String name) { + super(id, name); + } + + @Override + public void learn(Double numberOfHours){ + this.totalStudyTime = 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..7b644e6 --- /dev/null +++ b/src/main/java/com/github/curriculeon/Teacher.java @@ -0,0 +1,9 @@ +package com.github.curriculeon; + +public 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..9503022 --- /dev/null +++ b/src/test/java/com/github/curriculeon/TestInstructor.java @@ -0,0 +1,74 @@ +package com.github.curriculeon; + +import org.junit.Assert; +import org.junit.Test; + +public class TestInstructor { + @Test + public void testImplementation(){ + //given + Instructor instructor = new Instructor(null, null); + + //when + boolean outcome = instructor instanceof Teacher; + + //then + Assert.assertTrue(outcome); + } + + + @Test + public void testInheritance() { + //given + Instructor instructor = new Instructor(null, null); + + //when + boolean outcome = instructor instanceof Person; + + //then + Assert.assertTrue(outcome); + } + + + @Test + public void testTeach(){ + //given + Instructor instructor = new Instructor(null, null); + Learner learner = new Student(null, null); + Double numberOfHoursToTeach = 134.0; + Double preStudyTime = learner.getTotalStudyTime(); + Double expected = preStudyTime + numberOfHoursToTeach; + + //when + instructor.teach(learner, numberOfHoursToTeach); + Double actual = learner.getTotalStudyTime(); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void testLecture() { + //given + Teacher teacher = new Instructor(null, null); + Student baseStudent = new Student(null, null); + Learner[] learners = new Learner[]{ + new Student(0L, "John"), + new Student(1L, "Q"), + new Student(2L, "Public") + }; + Double numberOfHours = 128.0; + Double expected = numberOfHours/learners.length + baseStudent.getTotalStudyTime(); + + //when + teacher.lecture(learners, numberOfHours); + + //then + for (int i = 0; i < learners.length; i++) { + Learner learner = learners[i]; + Double actual = learner.getTotalStudyTime(); + Assert.assertEquals(expected, actual); + + } + } +} 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..c615113 --- /dev/null +++ b/src/test/java/com/github/curriculeon/TestStudent.java @@ -0,0 +1,56 @@ +package com.github.curriculeon; + +import org.junit.Assert; +import org.junit.Test; + +public class TestStudent { + //Create a testImplementation method that asserts that a Student + // is an instanceof a Learner. + @Test + public void testImplementation() { + //given + Student student = new Student(null, null); + + //when + Boolean result = student instanceof Learner; + + //then + Assert.assertTrue(result); + } + + //Create a testInheritance method that asserts that a Student is an + // instanceof a Person. + @Test + public void testInheritance() { + //given + Student student = new Student(null, null); + + //when + Boolean result = student instanceof Person; + + //then + Assert.assertTrue(result); + + } + + //Create a testLearn method that ensures a Student's totalStudyTime + // instance variable is incremented by the specified numberOfHours + // by invoking the .learn method. + @Test + public void testLearn() { + //given + Student student = new Student(null,null); + Double numberOfHours = 98.0; + Double preStudyTime = student.getTotalStudyTime(); + Double expected = preStudyTime + numberOfHours; + + //when + student.learn(numberOfHours); + Double actual = student.getTotalStudyTime(); + + //then + Assert.assertEquals(expected, actual, 0.01); + + } + +} From 7f681a53b83e10750b3c2eedf75bad3a568d793c Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 27 Jul 2020 12:42:56 -0400 Subject: [PATCH 4/7] part 6 without testing --- .../java/com/github/curriculeon/People.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/main/java/com/github/curriculeon/People.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..1581d74 --- /dev/null +++ b/src/main/java/com/github/curriculeon/People.java @@ -0,0 +1,59 @@ +package com.github.curriculeon; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class People implements Iterable { + List personList = new ArrayList<>(); + + public void add (Person person) { + this.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 remove(long id) { + for(Person person : personList) { + if (person.getId() == id) { + personList.remove(person); + } + } + } + + public void removeAll(List personList) { + personList.clear(); + } + + public int count(List personList) { + return personList.size(); + } + + public Object[] toArray(List personList) { + return personList.toArray(); + } + + public Iterator iterator(List personList) { + return personList.iterator() = new Iterator(); + } + + @Override + public Iterator iterator() { + return null; + } +} \ No newline at end of file From 2b6c0ccc6050eaf54d391c1124d5e7e15ec6880c Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 27 Jul 2020 22:08:33 -0400 Subject: [PATCH 5/7] completed through 8 --- .../com/github/curriculeon/Classroom.java | 7 +++ .../com/github/curriculeon/Instructors.java | 15 +++++ .../java/com/github/curriculeon/People.java | 26 +++++---- .../java/com/github/curriculeon/Students.java | 20 +++++++ .../github/curriculeon/TestInstructors.java | 24 ++++++++ .../com/github/curriculeon/TestPeople.java | 55 +++++++++++++++++++ .../com/github/curriculeon/TestStudents.java | 26 +++++++++ 7 files changed, 162 insertions(+), 11 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/Students.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..d235e24 --- /dev/null +++ b/src/main/java/com/github/curriculeon/Classroom.java @@ -0,0 +1,7 @@ +package com.github.curriculeon; + +public class Classroom { + private Students students; + private Instructors instructors; + +} 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..ef9ef2b --- /dev/null +++ b/src/main/java/com/github/curriculeon/Instructors.java @@ -0,0 +1,15 @@ +package com.github.curriculeon; + +public class Instructors extends People { + private static final Instructors instance = new Instructors(); + + public Instructors() { + this.add(new Instructor(0L, "Leon")); + this.add(new Instructor(1L, "Haseeb")); + } + + 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 1581d74..6ad673e 100644 --- a/src/main/java/com/github/curriculeon/People.java +++ b/src/main/java/com/github/curriculeon/People.java @@ -4,10 +4,11 @@ import java.util.Iterator; import java.util.List; -public class People implements Iterable { +public class People implements Iterable { List personList = new ArrayList<>(); public void add (Person person) { + this.personList.add(person); } @@ -21,10 +22,12 @@ public Person findById(long id) { } public Boolean contains(Person person) { + return personList.contains(person); } public void remove(Person person) { + personList.remove(person); } @@ -36,24 +39,25 @@ public void remove(long id) { } } - public void removeAll(List personList) { + public void removeAll() { + personList.clear(); } - public int count(List personList) { + public int count() { + return personList.size(); } - public Object[] toArray(List personList) { - return personList.toArray(); + public Person[] toArray() { + int arrayLength = personList.size(); + Person[] newArray = new Person[arrayLength]; + return personList.toArray(newArray); } - public Iterator iterator(List personList) { - return personList.iterator() = new Iterator(); - } + public Iterator iterator() { - @Override - public Iterator iterator() { - return null; + return personList.iterator(); } + } \ No newline at end of file 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..cbbc226 --- /dev/null +++ b/src/main/java/com/github/curriculeon/Students.java @@ -0,0 +1,20 @@ +package com.github.curriculeon; + +public class Students extends People { + private static final Students instance = new Students(); + + private Students(){ + super(); + this.add(new Student(0L, "Student A")); + this.add(new Student(1L, "Student B")); + this.add(new Student(2L, "Student C")); + + } + + public static Students getInstance(){ + + return instance; + } + + +} 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..69b1373 --- /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.util.Arrays; +import java.util.List; + +public class TestInstructors { + + @Test + public void test() { + Instructors instructors = Instructors.getInstance(); + List instructorNameList = Arrays.asList("Leon", "Haseeb"); + + Person[] instructorArray = instructors.toArray(); + for(int i = 0; i < instructorArray.length; i++) { + Person person = instructorArray[i]; + String personName = person.getName(); + boolean hasPersonWithName = instructorNameList.contains(personName); + 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..e8bf1db --- /dev/null +++ b/src/test/java/com/github/curriculeon/TestPeople.java @@ -0,0 +1,55 @@ +package com.github.curriculeon; + +import org.junit.Assert; +import org.junit.Test; + +public class TestPeople { + + @Test + public void testAdd() { + //given + People peopleList = new People(); + Person person1 = new Person(); + + //when + peopleList.add(person1); + + //then + Assert.assertTrue(peopleList.contains(person1)); + } + + @Test + public void testRemove() { + //given + People peopleList = new People(); + Person person1 = new Person(); + peopleList.add(person1); + Boolean expected = peopleList.contains(person1); + + //when + peopleList.remove(person1); + + //then + Assert.assertFalse(peopleList.contains(person1)); + } + + @Test + public void testFindById() { + //given + People peopleList = new People(); + Person person1 = new Person(575L, "Joe"); + peopleList.add(person1); + Boolean expected = peopleList.contains(person1); + + // when + peopleList.findById(575L); + + //then + Assert.assertTrue(peopleList.contains(peopleList.findById(575L))); + + + } + + + +} 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..d78fc8c --- /dev/null +++ b/src/test/java/com/github/curriculeon/TestStudents.java @@ -0,0 +1,26 @@ +package com.github.curriculeon; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; + +public class TestStudents { + + @Test + public void test() { + Students students = Students.getInstance(); + String[] studentNameArray = {"Student A", "Student B", "Student C"}; + List studentNameList = Arrays.asList(studentNameArray); + + Person[] studentArray = students.toArray(); + for(int i = 0; i < studentArray.length; i++) { + Person person = studentArray[i]; + String personName = person.getName(); + boolean hasPersonWithName = studentNameList.contains(personName); + Assert.assertTrue(hasPersonWithName); + } + } + +} From e5a16a9907937d685edb8c3abe4c932915867d2d Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 1 Aug 2020 11:43:49 -0400 Subject: [PATCH 6/7] tweaked formatting --- src/main/java/com/github/curriculeon/Instructors.java | 6 +++--- src/main/java/com/github/curriculeon/Students.java | 6 +++--- src/test/java/com/github/curriculeon/TestInstructors.java | 4 ++++ src/test/java/com/github/curriculeon/TestStudents.java | 4 ++++ 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/github/curriculeon/Instructors.java b/src/main/java/com/github/curriculeon/Instructors.java index ef9ef2b..0293ff6 100644 --- a/src/main/java/com/github/curriculeon/Instructors.java +++ b/src/main/java/com/github/curriculeon/Instructors.java @@ -1,7 +1,7 @@ package com.github.curriculeon; -public class Instructors extends People { - private static final Instructors instance = new Instructors(); +public final class Instructors extends People { + private static final Instructors INSTANCE = new Instructors(); public Instructors() { this.add(new Instructor(0L, "Leon")); @@ -9,7 +9,7 @@ public Instructors() { } public static Instructors getInstance() { - return instance; + return INSTANCE; } } diff --git a/src/main/java/com/github/curriculeon/Students.java b/src/main/java/com/github/curriculeon/Students.java index cbbc226..75c1eab 100644 --- a/src/main/java/com/github/curriculeon/Students.java +++ b/src/main/java/com/github/curriculeon/Students.java @@ -1,7 +1,7 @@ package com.github.curriculeon; -public class Students extends People { - private static final Students instance = new Students(); +public final class Students extends People { + private static final Students INSTANCE = new Students(); private Students(){ super(); @@ -13,7 +13,7 @@ private Students(){ public static Students getInstance(){ - return instance; + return INSTANCE; } diff --git a/src/test/java/com/github/curriculeon/TestInstructors.java b/src/test/java/com/github/curriculeon/TestInstructors.java index 69b1373..9098487 100644 --- a/src/test/java/com/github/curriculeon/TestInstructors.java +++ b/src/test/java/com/github/curriculeon/TestInstructors.java @@ -10,14 +10,18 @@ public class TestInstructors { @Test public void test() { + //given Instructors instructors = Instructors.getInstance(); List instructorNameList = Arrays.asList("Leon", "Haseeb"); + //when Person[] instructorArray = instructors.toArray(); for(int i = 0; i < instructorArray.length; i++) { Person person = instructorArray[i]; String personName = person.getName(); boolean hasPersonWithName = instructorNameList.contains(personName); + + //then Assert.assertTrue(hasPersonWithName); } } diff --git a/src/test/java/com/github/curriculeon/TestStudents.java b/src/test/java/com/github/curriculeon/TestStudents.java index d78fc8c..1cd48b3 100644 --- a/src/test/java/com/github/curriculeon/TestStudents.java +++ b/src/test/java/com/github/curriculeon/TestStudents.java @@ -10,15 +10,19 @@ public class TestStudents { @Test public void test() { + //given Students students = Students.getInstance(); String[] studentNameArray = {"Student A", "Student B", "Student C"}; List studentNameList = Arrays.asList(studentNameArray); + //when Person[] studentArray = students.toArray(); for(int i = 0; i < studentArray.length; i++) { Person person = studentArray[i]; String personName = person.getName(); boolean hasPersonWithName = studentNameList.contains(personName); + + //then Assert.assertTrue(hasPersonWithName); } } From 48b00605c40fe2808258f2c9ca23ec69f88e46f7 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 1 Aug 2020 13:17:15 -0400 Subject: [PATCH 7/7] progress before lunch; understanding more --- .../java/com/github/curriculeon/Classroom.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/curriculeon/Classroom.java b/src/main/java/com/github/curriculeon/Classroom.java index d235e24..3cb4990 100644 --- a/src/main/java/com/github/curriculeon/Classroom.java +++ b/src/main/java/com/github/curriculeon/Classroom.java @@ -1,7 +1,17 @@ package com.github.curriculeon; public class Classroom { - private Students students; - private Instructors instructors; + 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) { + Person person = instructors.findById(id); + Instructor instructor = (Instructor)person; + instructor.lecture((Learner[])students.toArray(), numberOfHours); + } }