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..11021fb --- /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 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/Learner.java b/src/main/java/com/github/curriculeon/Learner.java new file mode 100644 index 0000000..70a38dc --- /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/main/java/com/github/curriculeon/People.java b/src/main/java/com/github/curriculeon/People.java new file mode 100644 index 0000000..02e5100 --- /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/Person.java b/src/main/java/com/github/curriculeon/Person.java index 3c8350b..99b54e9 100644 --- a/src/main/java/com/github/curriculeon/Person.java +++ b/src/main/java/com/github/curriculeon/Person.java @@ -1,5 +1,28 @@ package com.github.curriculeon; public class Person { + private final long id; + private String name; + + Person(){ + id = 0; + 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; + } } 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..e2bda89 --- /dev/null +++ b/src/main/java/com/github/curriculeon/Student.java @@ -0,0 +1,25 @@ +package com.github.curriculeon; + +public class Student extends Person implements Learner { + private Double totalStudyTime = 0.0; + + public Student(){ + super(); + } + public Student(Long id, String name){ + super(id, name); + } + + public Student(Double numOfHours){ + super(); + learn(numOfHours); + } + public void learn(Double numberOfHours) { + totalStudyTime += numberOfHours; + } + + + public Double getTotalStudyTime() { + return totalStudyTime; + } +} 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; + } +} 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); +} 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..bcd8325 --- /dev/null +++ b/src/test/java/com/github/curriculeon/TestInstructor.java @@ -0,0 +1,75 @@ +package com.github.curriculeon; +import org.junit.Assert; +import org.junit.Test; + +public class TestInstructor { + public void testImplementation(){ + //Given + Object instructorOne = new Instructor(); + + //When + + //Then + Assert.assertTrue(instructorOne instanceof Teacher); + } + public void testInheritance(){ + //Given + Object instructorTwo = new Instructor(); + //When + + //Then + Assert.assertTrue(instructorTwo instanceof Person); + } + public void testTeach(Double hoursToAdd){ + //Given + Instructor instructorThree = new Instructor(); + Student studentOne = new Student(); + Double currentStudentHours = studentOne.getTotalStudyTime(); + Double expectedStudentHours = currentStudentHours + hoursToAdd; + + //When + instructorThree.teach(studentOne, hoursToAdd); + Double actualStudentHours = studentOne.getTotalStudyTime(); + + //Then + Assert.assertEquals(actualStudentHours, expectedStudentHours); + } + public void testLecture(Double hours){ + //Given + 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 + public void test0(){ + testImplementation(); + } + + @Test + 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/TestPerson.java b/src/test/java/com/github/curriculeon/TestPerson.java index 6c523fe..e6034c5 100644 --- a/src/test/java/com/github/curriculeon/TestPerson.java +++ b/src/test/java/com/github/curriculeon/TestPerson.java @@ -1,5 +1,40 @@ package com.github.curriculeon; - +import org.junit.Assert; +import org.junit.Test; public class TestPerson { + private void testConstructor(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); + } + + public void testSetName(String expectedString){ + Person person = new Person(); + + person.setName(expectedString); + String actualString = person.getName(); + + Assert.assertEquals(expectedString, actualString); + + } + + @Test + public void test0(){ + testConstructor(1, "Marcus"); + } + + @Test + public void test1(){ + testSetName("Marcus Katalenas"); + } + + @Test + public void test2(){ + testSetName(""); + } } 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..07edc03 --- /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 { + + public void testImplementation(){ + //Given + Student studentOne = new Student(); + //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 + + Assert.assertTrue(result); + } + 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); + } +} + + + +