diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 00000000..8f6ee9db --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 00000000..63e90019 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 00000000..712ab9d9 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__junit_junit_4_12.xml b/.idea/libraries/Maven__junit_junit_4_12.xml new file mode 100644 index 00000000..d4110417 --- /dev/null +++ b/.idea/libraries/Maven__junit_junit_4_12.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 00000000..f58bbc11 --- /dev/null +++ b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..25daa30c --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..711b3a53 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 00000000..e96534fb --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/interfaces-1.iml b/interfaces-1.iml new file mode 100644 index 00000000..4e3316bc --- /dev/null +++ b/interfaces-1.iml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index f0effe12..22cffbe3 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,19 @@ io.zipcoder interfaces-1 0.0.1-SNAPSHOT - jar + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + + jar interfaces-1 http://maven.apache.org diff --git a/src/main/java/io/zipcoder/interfaces/Educator.java b/src/main/java/io/zipcoder/interfaces/Educator.java new file mode 100644 index 00000000..3baba3b4 --- /dev/null +++ b/src/main/java/io/zipcoder/interfaces/Educator.java @@ -0,0 +1,28 @@ +package io.zipcoder.interfaces; + +public enum Educator implements Teacher{ + DOLIO(Instructors.getInstance().findById(101L)), + LEON(Instructors.getInstance().findById(102L)), + KRIS(Instructors.getInstance().findById(103L)); + + Instructor instructor; + Double timeWorked = 0.0; + + Educator(Instructor instructor) { + this.instructor = instructor; + } + + @Override + public void teach(Learner learner, double numberOfHours) { + this.instructor.teach(learner, numberOfHours); + this.timeWorked += numberOfHours; + } + + @Override + public void lecture(Learner[] learners, double numberOfHours) { + this.instructor.lecture(learners, numberOfHours); + this.timeWorked += numberOfHours; + } + + +} diff --git a/src/main/java/io/zipcoder/interfaces/Instructor.java b/src/main/java/io/zipcoder/interfaces/Instructor.java new file mode 100644 index 00000000..f8ec12ef --- /dev/null +++ b/src/main/java/io/zipcoder/interfaces/Instructor.java @@ -0,0 +1,21 @@ +package io.zipcoder.interfaces; + +public class Instructor extends Person implements Teacher{ + + Instructor(Long id, String name) { //default person. super cuz instructor is subclass + super(id, name); + } + + public void teach(Learner learner, double numberOfHours) { + learner.learn(numberOfHours); + } + + public void lecture(Learner[] learners, double numberOfHours) { + double numberOfHoursPerLearner = numberOfHours / learners.length; + for (Learner studentLearners : learners){ // for each Learner in array learners + studentLearners.learn(numberOfHoursPerLearner); //each learner can learn in + //divided hours by each student + //in learners array. + } + } +} diff --git a/src/main/java/io/zipcoder/interfaces/Instructors.java b/src/main/java/io/zipcoder/interfaces/Instructors.java new file mode 100644 index 00000000..6dd50fbe --- /dev/null +++ b/src/main/java/io/zipcoder/interfaces/Instructors.java @@ -0,0 +1,23 @@ +package io.zipcoder.interfaces; + +public final class Instructors extends People{ + + public static final Instructors INSTANCE = new Instructors(); + + private Instructors() { + this.add(new Instructor (101L, "Dolio")); + this.add(new Instructor (102L, "Leon")); + this.add(new Instructor (103L, "Kris")); + + } + + public static Instructors getInstance(){ + return INSTANCE; + } + + public Instructor[] toArray(){ + return elementList.toArray(new Instructor[0]); + } + + +} diff --git a/src/main/java/io/zipcoder/interfaces/Learner.java b/src/main/java/io/zipcoder/interfaces/Learner.java new file mode 100644 index 00000000..4d803a6a --- /dev/null +++ b/src/main/java/io/zipcoder/interfaces/Learner.java @@ -0,0 +1,10 @@ +package io.zipcoder.interfaces; + +public interface Learner { + + public void learn(double numberOfHours); + + public Double getTotalStudyTime(); + +} + diff --git a/src/main/java/io/zipcoder/interfaces/People.java b/src/main/java/io/zipcoder/interfaces/People.java new file mode 100644 index 00000000..45ca2ec0 --- /dev/null +++ b/src/main/java/io/zipcoder/interfaces/People.java @@ -0,0 +1,52 @@ +package io.zipcoder.interfaces; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public abstract class People implements Iterable{ + List elementList = new ArrayList(); + + + public void add(E element){ + elementList.add(element); + } + + public E findById(Long id) { + for (E element: elementList) { //enhanced for each Person in person list + if (element.getId().equals(id)) { + } return element; + } + return null; //need to return something + } + + public Boolean contains(E element) { + if (elementList.contains(element)) { + return true; + } + return false; // if personlist does not contain person return false + } + + public void remove(E element) { + elementList.remove(element); + } + + public void removeById(Long id) { + remove(findById(id)); //use find id method to remove id + } + + public void removeAll() { + elementList.clear(); + } + + public int count() { + return elementList.size(); + } + + public abstract E[] toArray(); + + @Override + public Iterator iterator() { + return elementList.iterator(); + } +} diff --git a/src/main/java/io/zipcoder/interfaces/Person.java b/src/main/java/io/zipcoder/interfaces/Person.java index fc6a3ffe..9fef2ca8 100644 --- a/src/main/java/io/zipcoder/interfaces/Person.java +++ b/src/main/java/io/zipcoder/interfaces/Person.java @@ -1,5 +1,25 @@ package io.zipcoder.interfaces; public class Person { + final Long id; + String name; + Person(Long id, String name){ + this.id = id; + this.name = name; + } + + public Long getId() { + return id; //cant this.id = id cuz final + } + + public String getName() { + return name; + } + + //public Long setId(){ this.id = id; } //cant set this.id = id cuz final + + public String setName() { + return this.name = name; + } } diff --git a/src/main/java/io/zipcoder/interfaces/Student.java b/src/main/java/io/zipcoder/interfaces/Student.java new file mode 100644 index 00000000..18e995ee --- /dev/null +++ b/src/main/java/io/zipcoder/interfaces/Student.java @@ -0,0 +1,20 @@ +package io.zipcoder.interfaces; + +public class Student extends Person implements Learner{ + double totalStudyTime; + Student(Long id, String name, double totalStudyTime) { + + super(id, name); + this.totalStudyTime = totalStudyTime; //forgot to put in for learn test + } + + public void learn(double numberOfHours) { + totalStudyTime = totalStudyTime + numberOfHours; + } + + public Double getTotalStudyTime() { + return totalStudyTime; + } + + +} diff --git a/src/main/java/io/zipcoder/interfaces/Students.java b/src/main/java/io/zipcoder/interfaces/Students.java new file mode 100644 index 00000000..0954dd00 --- /dev/null +++ b/src/main/java/io/zipcoder/interfaces/Students.java @@ -0,0 +1,45 @@ +package io.zipcoder.interfaces; + +public final class Students extends People{ //final makes it unextendable + + public static final Students INSTANCE = new Students(); + + private Students(){ + add(new Student(1L, "Me", 1.0)); + add(new Student(2L, "Zachs", 1.0)); + add(new Student(3L, "Manny", 1.0)); + add(new Student(4L, "Nisha", 1.0)); + add(new Student(5L, "Bobbi", 1.0)); + add(new Student(6L, "Tati", 1.0)); + add(new Student(7L, "Jen", 1.0)); + add(new Student(8L, "John", 1.0)); + add(new Student(9L, "Laura", 1.0)); + add(new Student(10L, "Ray", 1.0)); + add(new Student(11L, "Nick", 1.0)); + add(new Student(12L, "Zachk", 1.0)); + add(new Student(13L, "Dipinti", 1.0)); + add(new Student(14L, "Dee", 1.0)); + add(new Student(15L, "Sitara", 1.0)); + add(new Student(16L, "Char", 1.0)); + add(new Student(17L, "Nathan", 1.0)); + add(new Student(18L, "Jeremy", 1.0)); + add(new Student(19L, "Rustle", 1.0)); + + + + } + +// public Student[] toArray() { +// Student[] personArr = super.elementList.toArray(new Student[0]); +// return personArr; +// } + @Override + public Student[] toArray() { + return elementList.toArray(new Student[0]); + + } + + public static Students getInstance() { + return INSTANCE; + } +} diff --git a/src/main/java/io/zipcoder/interfaces/Teacher.java b/src/main/java/io/zipcoder/interfaces/Teacher.java new file mode 100644 index 00000000..6147fa1a --- /dev/null +++ b/src/main/java/io/zipcoder/interfaces/Teacher.java @@ -0,0 +1,7 @@ +package io.zipcoder.interfaces; + +public interface Teacher { + public void teach(Learner learner, double numberOfHours); + + public void lecture(Learner[] learners, double numberOfHours); +} diff --git a/src/main/java/io/zipcoder/interfaces/ZipCodeWilmington.java b/src/main/java/io/zipcoder/interfaces/ZipCodeWilmington.java new file mode 100644 index 00000000..80437eb1 --- /dev/null +++ b/src/main/java/io/zipcoder/interfaces/ZipCodeWilmington.java @@ -0,0 +1,39 @@ +package io.zipcoder.interfaces; + +import com.sun.org.apache.bcel.internal.generic.InstructionTargeter; + +import java.util.HashMap; +import java.util.Map; + +public class ZipCodeWilmington { + + private static final Students students = Students.getInstance(); + private static final Instructors instructors = Instructors.getInstance(); + private static final ZipCodeWilmington INSTANCE = new ZipCodeWilmington(); + + private ZipCodeWilmington(){ + } + + public static ZipCodeWilmington getInstance() { + return INSTANCE; + } + + public void hostLecture(Educator teacher, double numberOfHours){ + teacher.lecture(students.elementList.toArray(new Learner[0]), numberOfHours); + } + + public void hostLecture(Long id, double numberOfHours){ + Teacher teacher = (Teacher) instructors.findById(id); + Learner[] learner = students.elementList.toArray(new Learner[0]); + teacher.lecture(learner, numberOfHours); + } + + public Map getStudyMap() { + Map map = new HashMap<>(); + for (int i = 0; i < students.elementList.size(); i++) { + Student s = (Student) students.elementList.get(i); + map.put(s,s.getTotalStudyTime()); + } + return map; + } +} diff --git a/src/test/java/io/zipcoder/interfaces/TestEducator.java b/src/test/java/io/zipcoder/interfaces/TestEducator.java new file mode 100644 index 00000000..dd5f7c4e --- /dev/null +++ b/src/test/java/io/zipcoder/interfaces/TestEducator.java @@ -0,0 +1,41 @@ +package io.zipcoder.interfaces; + +import org.junit.Assert; +import org.junit.Test; + +public class TestEducator { + + @Test + public void testEducatorInstance() { + Instructor expected = Instructors.getInstance().findById(101L); + Instructor actual = Educator.DOLIO.instructor; + + Assert.assertEquals(expected,actual); + + } + + @Test + public void testTeachEnum(){ + + Student student = Students.getInstance().findById(1L); + Educator.DOLIO.teach(student,2); + + Double expected = 3.0; + Double actual = student.totalStudyTime; + + Assert.assertEquals(expected, actual); + } + + @Test + public void testLectureEnum() { + Student[] students = Students.getInstance().toArray(); + Educator.DOLIO.lecture(students, 19); + + Double expected = 2.0; + Double actual = students[0].getTotalStudyTime(); + + Assert.assertEquals(expected, actual); + } + + +} diff --git a/src/test/java/io/zipcoder/interfaces/TestInstructor.java b/src/test/java/io/zipcoder/interfaces/TestInstructor.java new file mode 100644 index 00000000..6e1a4ffd --- /dev/null +++ b/src/test/java/io/zipcoder/interfaces/TestInstructor.java @@ -0,0 +1,35 @@ +package io.zipcoder.interfaces; + +import org.junit.Assert; +import org.junit.Test; + +public class TestInstructor { + + @Test + public void testImplementation(){ + Instructor instructor = new Instructor(Long.MAX_VALUE,"Dusty"); + + Assert.assertTrue(instructor instanceof Teacher); + } + + @Test + public void testInheritance(){ + Instructor instructor = new Instructor(Long.MIN_VALUE,"DaeDae"); + + Assert.assertTrue(instructor instanceof Person); + } + + @Test + public void testTeach(){ + Instructor instructor = new Instructor(Long.MIN_VALUE, "KidCudi"); + Learner student = new Student(Long.MAX_VALUE, "KanyeWest", 23.0); + double numberOfHours = 10.0; + + instructor.teach(student, numberOfHours); + Double expected = 33.0; + Double actual = student.getTotalStudyTime(); + + Assert.assertEquals(expected, actual); + + } +} diff --git a/src/test/java/io/zipcoder/interfaces/TestInstructors.java b/src/test/java/io/zipcoder/interfaces/TestInstructors.java new file mode 100644 index 00000000..30d038fd --- /dev/null +++ b/src/test/java/io/zipcoder/interfaces/TestInstructors.java @@ -0,0 +1,35 @@ +package io.zipcoder.interfaces; + +import org.junit.Assert; +import org.junit.Test; + +public class TestInstructors { + + @Test + public void whereAllMyProfsAt() { + Instructors instructors = Instructors.getInstance(); + + Instructor dolio = (new Instructor(101L, "Dolio")); + Instructor leon = (new Instructor(102L, "Leon")); + Instructor kris = (new Instructor(103L, "Kris")); + + int expected = 3; + int actual = instructors.count(); + + Assert.assertEquals(expected, actual); + } + +// @Test +// public void whereProfId() { +// Instructors instructors = Instructors.getInstance(); +// +// Instructor dolio = (new Instructor(1L, "Dolio")); +// Instructor leon = (new Instructor(2L, "Leon")); +// Instructor kris = (new Instructor(3L, "Kris")); +// +// Person actual2 = instructors.findById(2L); +// Person expected2 = leon; +// +// Assert.assertEquals(expected2, actual2); +// } @@@@singleton always diff id +} diff --git a/src/test/java/io/zipcoder/interfaces/TestPeople.java b/src/test/java/io/zipcoder/interfaces/TestPeople.java new file mode 100644 index 00000000..9434db45 --- /dev/null +++ b/src/test/java/io/zipcoder/interfaces/TestPeople.java @@ -0,0 +1,64 @@ +package io.zipcoder.interfaces; + +import org.junit.Assert; +import org.junit.Test; + +public class TestPeople { + /** + * Create a TestPeople class. + * Create a testAdd method which ensures that our + * personList in our People class populated with respective + * Person objects following invokation of the add method. + * + * Create a testRemove method which ensures that the + * personList in a People object is depopulated with a respective + * Person object following the invokation of the remove method. + * + * Create a testFindById method which ensures that a respective + * Person object with a respective id field is returned upon + * invokation of the findById method on a respective People object. + */ + + + @Test + public void testAdd() { + Person person = new Person(1L, "Taco"); + Person person2 = new Person(2L, "TacoTuesday"); + People personList = Students.getInstance(); + + personList.add(person); + personList.add(person2); + int expected = 21; + int actual = personList.count(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void testRemove() { + Person person = new Person(1L, "Taco"); + Person person2 = new Person(2L, "TacoTuesday"); + People personList = Students.getInstance(); + + personList.add(person); + personList.add(person2); + personList.remove(person); + int expected = 22; + int actual = personList.count(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void testFindById() { + Students personList = Students.getInstance(); + + + String expected = "Me"; + String actual = personList.findById(1L).getName(); + + + Assert.assertEquals(expected, actual); + + } +} diff --git a/src/test/java/io/zipcoder/interfaces/TestPerson.java b/src/test/java/io/zipcoder/interfaces/TestPerson.java index d64cd2f0..18868d93 100644 --- a/src/test/java/io/zipcoder/interfaces/TestPerson.java +++ b/src/test/java/io/zipcoder/interfaces/TestPerson.java @@ -1,5 +1,36 @@ package io.zipcoder.interfaces; +import org.junit.Assert; +import org.junit.Test; + public class TestPerson { + @Test + public void PersonConstructorTest(){ + Long id = Long.MAX_VALUE; + String name = "Tacodog"; + Person person = new Person(id, name); + + Long expectedId = id; + Long actualId = person.getId(); + + String expectedName = "Tacodog"; + String actualName = person.getName(); + + Assert.assertEquals(expectedId, actualId); + Assert.assertEquals(expectedName, actualName); + } + + @Test + public void TestSetName(){ + Long id = Long.MIN_VALUE; + String name = "Tacocat"; + Person person = new Person(id, name); + + String expectedName = name; + + String actualName = person.getName(); + + Assert.assertEquals(expectedName, actualName); + } } diff --git a/src/test/java/io/zipcoder/interfaces/TestStudent.java b/src/test/java/io/zipcoder/interfaces/TestStudent.java new file mode 100644 index 00000000..f2aa3dfc --- /dev/null +++ b/src/test/java/io/zipcoder/interfaces/TestStudent.java @@ -0,0 +1,34 @@ +package io.zipcoder.interfaces; + +import org.junit.Assert; +import org.junit.Test; + +public class TestStudent { + + @Test + public void inheritanceTest(){ + Student student = new Student(Long.MIN_VALUE, "Danielsan",40); //created a student + + Assert.assertTrue(student instanceof Learner); //should be true if student is learner + } + + @Test + public void StudentPersonTest() { + Student student = new Student(Long.MAX_VALUE,"DoctorDoom",50.0); + + Assert.assertTrue(student instanceof Person); + } + + @Test + public void testlearn() { + double numberOfHours = 20.0; + Student student = new Student(Long.MAX_VALUE, "Brainiac", 80.0); + + Double expectedHours = 100.0; + student.learn(numberOfHours); + Double actualHours = student.getTotalStudyTime(); + + Assert.assertEquals(expectedHours,actualHours); + + } +} diff --git a/src/test/java/io/zipcoder/interfaces/TestStudents.java b/src/test/java/io/zipcoder/interfaces/TestStudents.java new file mode 100644 index 00000000..5f4f9bcb --- /dev/null +++ b/src/test/java/io/zipcoder/interfaces/TestStudents.java @@ -0,0 +1,37 @@ +package io.zipcoder.interfaces; + +import org.junit.Assert; +import org.junit.Test; + +public class TestStudents { + + @Test + public void whereAllMyPeepsAt() { + Students students = Students.getInstance(); + + Student Rex = (new Student(1L, "Me", 1.0)); + Student Zachk = (new Student(2L, "Zachk", 1.0)); + Student manny = (new Student(3L, "Manny", 1.0)); + Student nisha = (new Student(4L, "Nisha", 1.0)); + Student bobbi = (new Student(5L, "Bobbi", 1.0)); + Student tati = (new Student(6L, "Tati", 1.0)); + Student jen = (new Student(7L, "Jen", 1.0)); + Student john = (new Student(8L, "John", 1.0)); + Student laura = (new Student(9L, "Laura", 1.0)); + Student ray = (new Student(10L, "Ray", 1.0)); + Student nick = (new Student(11L, "Nick", 1.0)); + Student zachs = (new Student(12L, "Zachs", 1.0)); + Student dipinti = (new Student(13L, "Dipinti", 1.0)); + Student dee = (new Student(14L, "Dee", 1.0)); + Student sitara = (new Student(15L, "Sitara", 1.0)); + Student charn = (new Student(16L, "Char", 1.0)); + Student nathan = (new Student(17L, "Nathan", 1.0)); + Student jeremy =(new Student(18L, "Jeremy", 1.0)); + Student rustle =(new Student(19L, "Rustle", 1.0)); + + int expected = 22; + int actual = students.count(); + + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/io/zipcoder/interfaces/TestZipCodeWilmington.java b/src/test/java/io/zipcoder/interfaces/TestZipCodeWilmington.java new file mode 100644 index 00000000..98dbff1a --- /dev/null +++ b/src/test/java/io/zipcoder/interfaces/TestZipCodeWilmington.java @@ -0,0 +1,34 @@ +package io.zipcoder.interfaces; + +import org.junit.Assert; +import org.junit.Test; + +public class TestZipCodeWilmington { + + @Test + public void testHostLecture() { + Students students = Students.getInstance(); + ZipCodeWilmington zipcode = ZipCodeWilmington.getInstance(); + //19 students, each with 1 hour study time = 1 hour per student. + + Double expected = 2.0; + zipcode.hostLecture(101L, 19); + Double actual = zipcode.getStudyMap().get(students.findById(3L)); + + Assert.assertEquals(expected, actual); + + + } + + @Test + public void testEnumHostLecture() { + ZipCodeWilmington zipcodey = ZipCodeWilmington.getInstance(); + Educator leon = Educator.LEON; + + zipcodey.hostLecture(leon, 19.0); + Double expected = 19.0; + Double actual = leon.timeWorked; + + Assert.assertEquals(expected, actual); + } +}