From 379f28f3e54f9fba8ee9e8cd21673dea3707ad63 Mon Sep 17 00:00:00 2001
From: John Tokhi <56596400+tokhij@users.noreply.github.com>
Date: Sat, 23 Nov 2019 22:34:53 -0500
Subject: [PATCH 1/6] at part 4
---
.idea/.gitignore | 3 +
.idea/.name | 1 +
.idea/compiler.xml | 16 ++++++
.idea/encodings.xml | 6 ++
.idea/libraries/Maven__junit_junit_4_12.xml | 13 +++++
.../Maven__org_hamcrest_hamcrest_core_1_3.xml | 13 +++++
.idea/misc.xml | 13 +++++
.idea/modules.xml | 8 +++
.idea/vcs.xml | 6 ++
interfaces-1.iml | 16 ++++++
.../java/io/zipcoder/interfaces/Learner.java | 7 +++
.../java/io/zipcoder/interfaces/Person.java | 18 ++++++
.../java/io/zipcoder/interfaces/Student.java | 18 ++++++
.../java/io/zipcoder/interfaces/Teacher.java | 8 +++
.../io/zipcoder/interfaces/TestPerson.java | 26 +++++++++
.../io/zipcoder/interfaces/TestStudent.java | 55 +++++++++++++++++++
16 files changed, 227 insertions(+)
create mode 100644 .idea/.gitignore
create mode 100644 .idea/.name
create mode 100644 .idea/compiler.xml
create mode 100644 .idea/encodings.xml
create mode 100644 .idea/libraries/Maven__junit_junit_4_12.xml
create mode 100644 .idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml
create mode 100644 .idea/misc.xml
create mode 100644 .idea/modules.xml
create mode 100644 .idea/vcs.xml
create mode 100644 interfaces-1.iml
create mode 100644 src/main/java/io/zipcoder/interfaces/Learner.java
create mode 100644 src/main/java/io/zipcoder/interfaces/Student.java
create mode 100644 src/main/java/io/zipcoder/interfaces/Teacher.java
create mode 100644 src/test/java/io/zipcoder/interfaces/TestStudent.java
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 00000000..0e40fe8f
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+
+# Default ignored files
+/workspace.xml
\ No newline at end of file
diff --git a/.idea/.name b/.idea/.name
new file mode 100644
index 00000000..a0f2c3a1
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+interfaces-1
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 00000000..fdc60f4f
--- /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..b26911bd
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ 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..d30d09e2
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
\ 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/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 00000000..35eb1ddf
--- /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..0ddf51c1
--- /dev/null
+++ b/interfaces-1.iml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
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..123cc944
--- /dev/null
+++ b/src/main/java/io/zipcoder/interfaces/Learner.java
@@ -0,0 +1,7 @@
+package io.zipcoder.interfaces;
+
+public interface Learner {
+ public void learn(double numberOfHours);
+
+ public Double getTotalStudyTime();
+}
diff --git a/src/main/java/io/zipcoder/interfaces/Person.java b/src/main/java/io/zipcoder/interfaces/Person.java
index fc6a3ffe..c744ab95 100644
--- a/src/main/java/io/zipcoder/interfaces/Person.java
+++ b/src/main/java/io/zipcoder/interfaces/Person.java
@@ -1,5 +1,23 @@
package io.zipcoder.interfaces;
public class Person {
+ final long id;
+ String name;
+
+ public Person(long id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+ public long getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ 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..f38f70ab
--- /dev/null
+++ b/src/main/java/io/zipcoder/interfaces/Student.java
@@ -0,0 +1,18 @@
+package io.zipcoder.interfaces;
+
+public class Student extends Person implements Learner {
+ double totalStudyTime;
+
+ public Student(long id, String name) {
+ super(id, name);
+ }
+
+ public void learn(double numberOfHours){
+ totalStudyTime = numberOfHours + totalStudyTime;
+ }
+
+ public Double getTotalStudyTime(){
+ return totalStudyTime;
+ }
+
+}
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..9a67c19f
--- /dev/null
+++ b/src/main/java/io/zipcoder/interfaces/Teacher.java
@@ -0,0 +1,8 @@
+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/test/java/io/zipcoder/interfaces/TestPerson.java b/src/test/java/io/zipcoder/interfaces/TestPerson.java
index d64cd2f0..98ec091d 100644
--- a/src/test/java/io/zipcoder/interfaces/TestPerson.java
+++ b/src/test/java/io/zipcoder/interfaces/TestPerson.java
@@ -1,5 +1,31 @@
package io.zipcoder.interfaces;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
public class TestPerson {
+ Person person;
+
+ @Before
+ public void testConstructor() {
+ person = new Person(01, "Johnny");
+ }
+
+ @Test
+ public void testSetName(){
+ String expectedName = "Johnny";
+ long expectedId = 01;
+
+ String actualName = person.getName();
+ long actualId = person.getId();
+
+ Assert.assertEquals(expectedName, actualName);
+ Assert.assertEquals(expectedId, actualId);
+ }
+
+
+
+
}
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..bedc7848
--- /dev/null
+++ b/src/test/java/io/zipcoder/interfaces/TestStudent.java
@@ -0,0 +1,55 @@
+package io.zipcoder.interfaces;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestStudent {
+ Student student;
+
+ @Before
+ public void testConst(){
+ student = new Student(01, "Johnny");
+ }
+
+ @Test
+ public void testImplementation(){
+ boolean studentIsLearner;
+ if(student instanceof Learner){
+ studentIsLearner = true;
+ }
+ else{
+ studentIsLearner = false;
+ }
+
+ Assert.assertTrue(studentIsLearner);
+ }
+
+ @Test
+ public void testInheritance(){
+ boolean studentIsPerson;
+ if(student instanceof Person){
+ studentIsPerson = true;
+ }
+ else{
+ studentIsPerson = false;
+ }
+
+ Assert.assertTrue(studentIsPerson);
+ }
+
+ @Test
+ public void testLearn(){
+ student.totalStudyTime = 1.0;
+ student.learn(1.5);
+
+ Double expectedTime = 2.5;
+ Double actualTime = student.getTotalStudyTime();
+
+ Assert.assertEquals(expectedTime, actualTime);
+ }
+
+
+
+
+}
From 5056ce4ddbe9a687827cf2dd1d9994c4c9c1844e Mon Sep 17 00:00:00 2001
From: John Tokhi <56596400+tokhij@users.noreply.github.com>
Date: Sat, 23 Nov 2019 23:03:01 -0500
Subject: [PATCH 2/6] at part 6.1
---
.../io/zipcoder/interfaces/Instructor.java | 22 ++++++
.../zipcoder/interfaces/TestInstructor.java | 68 +++++++++++++++++++
2 files changed, 90 insertions(+)
create mode 100644 src/main/java/io/zipcoder/interfaces/Instructor.java
create mode 100644 src/test/java/io/zipcoder/interfaces/TestInstructor.java
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..1fbd55d2
--- /dev/null
+++ b/src/main/java/io/zipcoder/interfaces/Instructor.java
@@ -0,0 +1,22 @@
+package io.zipcoder.interfaces;
+
+public class Instructor extends Person implements Teacher {
+
+ public Instructor(long id, String name) {
+ 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 (int i = 0; i < learners.length; i++) {
+ learners[i].learn(numberOfHoursPerLearner);
+ }
+ }
+
+
+}
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..6d093cbb
--- /dev/null
+++ b/src/test/java/io/zipcoder/interfaces/TestInstructor.java
@@ -0,0 +1,68 @@
+package io.zipcoder.interfaces;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestInstructor {
+ Instructor instructor;
+ Student student;
+ Student student2;
+
+ @Before
+ public void testContr(){
+ instructor = new Instructor(11, "Zan");
+ student = new Student(01, "Johnny");
+ student2 = new Student(02, "Elliot");
+ }
+
+ @Test
+ public void testImplementation(){
+ boolean instructorIsTeacher;
+ if(instructor instanceof Teacher){
+ instructorIsTeacher= true;
+ }
+ else{
+ instructorIsTeacher = false;
+ }
+ Assert.assertTrue(instructorIsTeacher);
+ }
+
+ @Test
+ public void testInheritance(){
+ boolean instructorIsTeacher;
+ if(instructor instanceof Teacher){
+ instructorIsTeacher = true;
+ }
+ else{
+ instructorIsTeacher = false;
+ }
+ Assert.assertTrue(instructorIsTeacher);
+ }
+
+ @Test
+ public void testTeach(){
+ instructor.teach(student, 3);
+
+ Double expectedTime = 3.0;
+ Double actualTime = student.getTotalStudyTime();
+
+ Assert.assertEquals(expectedTime, actualTime);
+ }
+
+ @Test
+ public void testLecture(){
+ Learner[] learners = {student, student2};
+ instructor.lecture(learners,6);
+
+ Double expected = 3.0;
+ Double actual = student.getTotalStudyTime();
+
+ Assert.assertEquals(expected, actual);
+ }
+
+
+
+
+
+}
From ed9ab29807812d9e3465ad4eb780dcec9446e621 Mon Sep 17 00:00:00 2001
From: John Tokhi <56596400+tokhij@users.noreply.github.com>
Date: Sun, 24 Nov 2019 02:19:32 -0500
Subject: [PATCH 3/6] last test for 6.0 needs to pass
---
.idea/uiDesigner.xml | 124 ++++++++++++++++++
.../java/io/zipcoder/interfaces/People.java | 63 +++++++++
.../java/io/zipcoder/interfaces/Person.java | 16 +++
.../io/zipcoder/interfaces/TestPeople.java | 59 +++++++++
4 files changed, 262 insertions(+)
create mode 100644 .idea/uiDesigner.xml
create mode 100644 src/main/java/io/zipcoder/interfaces/People.java
create mode 100644 src/test/java/io/zipcoder/interfaces/TestPeople.java
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/src/main/java/io/zipcoder/interfaces/People.java b/src/main/java/io/zipcoder/interfaces/People.java
new file mode 100644
index 00000000..865ba98b
--- /dev/null
+++ b/src/main/java/io/zipcoder/interfaces/People.java
@@ -0,0 +1,63 @@
+package io.zipcoder.interfaces;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class People implements Iterable {
+ List personList = new ArrayList();
+ Person person = new Person(01, "Johnny");
+
+ public Iterator iterator(){
+ return personList.iterator();
+ }
+
+ public void add(Person person){
+ personList.add(person);
+ }
+
+ public Person findById(long id){
+ for (int i = 0; i < personList.size(); i++) {
+ if(personList.get(i).getId() == id){
+ return person;
+ }
+ }
+ return null;
+ }
+
+ public boolean contains(Person person){
+ if(personList.contains(person)){
+ return true;
+ }
+ return false;
+ }
+
+ public void remove(Person person){
+ personList.remove(person);
+ }
+
+ public void removeById(long id) {
+ for (int i = 0; i < personList.size(); i++) {
+ if (personList.get(i).getId() == id) {
+ personList.remove(i);
+ }
+ }
+ }
+
+ public void removeAll(){
+ personList.removeAll(personList);
+ }
+
+ public Integer count(){
+ return personList.size();
+ }
+
+ public String[] toArray(){
+ String[] newArr = personList.toArray(new String[0]);
+ return newArr;
+ }
+
+
+
+}
diff --git a/src/main/java/io/zipcoder/interfaces/Person.java b/src/main/java/io/zipcoder/interfaces/Person.java
index c744ab95..b8f5b6ac 100644
--- a/src/main/java/io/zipcoder/interfaces/Person.java
+++ b/src/main/java/io/zipcoder/interfaces/Person.java
@@ -1,5 +1,7 @@
package io.zipcoder.interfaces;
+import java.util.Objects;
+
public class Person {
final long id;
String name;
@@ -16,6 +18,20 @@ public String getName() {
return name;
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof Person)) return false;
+ Person person = (Person) o;
+ return getId() == person.getId() &&
+ getName().equals(person.getName());
+ }
+
+// @Override
+// public int hashCode() {
+// return Objects.hash(getId(), getName());
+// }
+
public void setName(String name) {
this.name = name;
}
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..4913522e
--- /dev/null
+++ b/src/test/java/io/zipcoder/interfaces/TestPeople.java
@@ -0,0 +1,59 @@
+package io.zipcoder.interfaces;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class TestPeople {
+ People personList;
+ Person person;
+ Person person2;
+ Person person3;
+
+
+ @Before
+ public void testContr(){
+ personList = new People();
+ person = new Person(11, "Zan");
+ person2 = new Person(01, "Johnny");
+ person3 = new Person(02, "Elliot");
+ }
+
+ @Test
+ public void testAdd(){
+ personList.add(person);
+
+ Integer expected = 1;
+ Integer actual = personList.personList.size();
+
+ Assert.assertEquals(expected,actual);
+ }
+
+ @Test
+ public void testRemove(){
+ personList.add(person);
+ personList.add(person2);
+ personList.add(person3);
+ personList.remove(person);
+
+ Integer expected = 2;
+ Integer actual = personList.personList.size();
+
+ Assert.assertEquals(expected,actual);
+ }
+
+ @Test
+ public void testFindById(){
+ personList.add(person);
+
+
+ Person expected = person;
+ Person actualId = personList.findById(person.getId());
+
+ Assert.assertEquals(expected,actualId);
+ }
+
+}
From 8f89ad2be7b01348fad52ca94b52c46ca734d0e7 Mon Sep 17 00:00:00 2001
From: John Tokhi <56596400+tokhij@users.noreply.github.com>
Date: Sun, 24 Nov 2019 21:58:56 -0500
Subject: [PATCH 4/6] finished part 7 w tests
---
.../java/io/zipcoder/interfaces/Person.java | 22 +++++++-------
.../java/io/zipcoder/interfaces/Students.java | 24 +++++++++++++++
.../io/zipcoder/interfaces/TestPeople.java | 30 ++++++++-----------
.../io/zipcoder/interfaces/TestStudents.java | 25 ++++++++++++++++
4 files changed, 73 insertions(+), 28 deletions(-)
create mode 100644 src/main/java/io/zipcoder/interfaces/Students.java
create mode 100644 src/test/java/io/zipcoder/interfaces/TestStudents.java
diff --git a/src/main/java/io/zipcoder/interfaces/Person.java b/src/main/java/io/zipcoder/interfaces/Person.java
index b8f5b6ac..b4e3e1b9 100644
--- a/src/main/java/io/zipcoder/interfaces/Person.java
+++ b/src/main/java/io/zipcoder/interfaces/Person.java
@@ -18,19 +18,19 @@ public String getName() {
return name;
}
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof Person)) return false;
- Person person = (Person) o;
- return getId() == person.getId() &&
- getName().equals(person.getName());
- }
-
// @Override
-// public int hashCode() {
-// return Objects.hash(getId(), getName());
+// public boolean equals(Object o) {
+// if (this == o) return true;
+// if (!(o instanceof Person)) return false;
+// Person person = (Person) o;
+// return getId() == person.getId() &&
+// getName().equals(person.getName());
// }
+//
+//// @Override
+//// public int hashCode() {
+//// return Objects.hash(getId(), getName());
+//// }
public void setName(String name) {
this.name = name;
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..47366bce
--- /dev/null
+++ b/src/main/java/io/zipcoder/interfaces/Students.java
@@ -0,0 +1,24 @@
+package io.zipcoder.interfaces;
+
+public final class Students extends People{
+
+ private static final Students INSTANCE= new Students();
+
+ private Students(){
+ super.add(new Student(05, "Ban"));
+ super.add(new Student(06, "chod"));
+ }
+
+ public Student[] getStudentArray(){
+ return new Student[0];
+ }
+
+ public static Students getInstance(){
+ if(INSTANCE != null){
+ return INSTANCE;
+ }
+ else{
+ return INSTANCE;
+ }
+ }
+}
diff --git a/src/test/java/io/zipcoder/interfaces/TestPeople.java b/src/test/java/io/zipcoder/interfaces/TestPeople.java
index 4913522e..2c3e60c5 100644
--- a/src/test/java/io/zipcoder/interfaces/TestPeople.java
+++ b/src/test/java/io/zipcoder/interfaces/TestPeople.java
@@ -4,11 +4,8 @@
import org.junit.Before;
import org.junit.Test;
-import java.util.ArrayList;
-import java.util.List;
-
public class TestPeople {
- People personList;
+ People peopleObject;
Person person;
Person person2;
Person person3;
@@ -16,7 +13,7 @@ public class TestPeople {
@Before
public void testContr(){
- personList = new People();
+ peopleObject = new People();
person = new Person(11, "Zan");
person2 = new Person(01, "Johnny");
person3 = new Person(02, "Elliot");
@@ -24,36 +21,35 @@ public void testContr(){
@Test
public void testAdd(){
- personList.add(person);
+ peopleObject.add(person);
Integer expected = 1;
- Integer actual = personList.personList.size();
+ Integer actual = peopleObject.personList.size();
Assert.assertEquals(expected,actual);
}
@Test
public void testRemove(){
- personList.add(person);
- personList.add(person2);
- personList.add(person3);
- personList.remove(person);
+ peopleObject.add(person2);
+ peopleObject.add(person3);
+ peopleObject.remove(person2);
- Integer expected = 2;
- Integer actual = personList.personList.size();
+ Integer expected = 1;
+ Integer actual = peopleObject.personList.size();
Assert.assertEquals(expected,actual);
}
@Test
public void testFindById(){
- personList.add(person);
+ peopleObject.add(person2);
- Person expected = person;
- Person actualId = personList.findById(person.getId());
+ Person expected = person2;
+ Person actualId = peopleObject.findById(1);
- Assert.assertEquals(expected,actualId);
+ Assert.assertEquals(expected.getId(),actualId.getId());
}
}
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..eef34b30
--- /dev/null
+++ b/src/test/java/io/zipcoder/interfaces/TestStudents.java
@@ -0,0 +1,25 @@
+package io.zipcoder.interfaces;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestStudents {
+
+ @Test
+ public void test1(){
+ Long [] studentArray = {5L, 6L};
+ Students actual = Students.getInstance();
+
+ for (int i = 0; i < studentArray.length; i++) {
+ Person actualStudent = actual.findById(studentArray[i]);
+ }
+
+ Assert.assertTrue(actual != null);
+
+
+ }
+
+
+
+
+}
From 80225ee9c270acaa0be728b22229bbe57be016d3 Mon Sep 17 00:00:00 2001
From: John Tokhi <56596400+tokhij@users.noreply.github.com>
Date: Sun, 24 Nov 2019 22:52:56 -0500
Subject: [PATCH 5/6] stuck on test part 9
---
.../io/zipcoder/interfaces/Instructors.java | 32 ++++++++++++++++++
.../java/io/zipcoder/interfaces/People.java | 33 +++++++++++--------
.../java/io/zipcoder/interfaces/Students.java | 8 ++---
.../interfaces/ZipCodeWilmington.java | 30 +++++++++++++++++
.../zipcoder/interfaces/TestInstructors.java | 21 ++++++++++++
.../io/zipcoder/interfaces/TestStudents.java | 7 ++--
.../interfaces/TestZipCodeWilmington.java | 24 ++++++++++++++
7 files changed, 134 insertions(+), 21 deletions(-)
create mode 100644 src/main/java/io/zipcoder/interfaces/Instructors.java
create mode 100644 src/main/java/io/zipcoder/interfaces/ZipCodeWilmington.java
create mode 100644 src/test/java/io/zipcoder/interfaces/TestInstructors.java
create mode 100644 src/test/java/io/zipcoder/interfaces/TestZipCodeWilmington.java
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..28c4382f
--- /dev/null
+++ b/src/main/java/io/zipcoder/interfaces/Instructors.java
@@ -0,0 +1,32 @@
+package io.zipcoder.interfaces;
+
+import java.util.ArrayList;
+
+public final class Instructors extends People{
+
+ private static final Instructors INSTANCE = new Instructors();
+
+ private Instructors(){
+ ArrayList instructorZan = new ArrayList();
+ instructorZan.add(0,"ZANN");
+ instructorZan.add(1,"is Annoying");
+
+ for (int i = 0; i < instructorZan.size(); i++) {
+ super.add(new Instructor(i,instructorZan.get(i)));
+ }
+ }
+
+ public Instructor[] toArray() {
+ return new Instructor[0];
+ }
+
+ public static Instructors getInstance(){
+ if(INSTANCE != null){
+ return INSTANCE;
+ }
+ else{
+ return INSTANCE;
+ }
+ }
+
+}
diff --git a/src/main/java/io/zipcoder/interfaces/People.java b/src/main/java/io/zipcoder/interfaces/People.java
index 865ba98b..7ea9e7ec 100644
--- a/src/main/java/io/zipcoder/interfaces/People.java
+++ b/src/main/java/io/zipcoder/interfaces/People.java
@@ -5,19 +5,24 @@
import java.util.Iterator;
import java.util.List;
-public class People implements Iterable {
- List personList = new ArrayList();
- Person person = new Person(01, "Johnny");
+public abstract class People {
+ ArrayList personList;
+ E person = null;
+// Person person = new Person(01, "Johnny");
- public Iterator iterator(){
- return personList.iterator();
+ public People(){
+ personList = new ArrayList();
}
- public void add(Person person){
+// public Iterator iterator(){
+// return personList.iterator();
+// }
+
+ public void add(E person){
personList.add(person);
}
- public Person findById(long id){
+ public E findById(long id){
for (int i = 0; i < personList.size(); i++) {
if(personList.get(i).getId() == id){
return person;
@@ -26,14 +31,14 @@ public Person findById(long id){
return null;
}
- public boolean contains(Person person){
+ public boolean contains(E person){
if(personList.contains(person)){
return true;
}
return false;
}
- public void remove(Person person){
+ public void remove(E person){
personList.remove(person);
}
@@ -53,10 +58,12 @@ public Integer count(){
return personList.size();
}
- public String[] toArray(){
- String[] newArr = personList.toArray(new String[0]);
- return newArr;
- }
+ public abstract E[] toArray();
+
+// public String[] toArray(){
+// String[] newArr = personList.toArray(new String[0]);
+// return newArr;
+// }
diff --git a/src/main/java/io/zipcoder/interfaces/Students.java b/src/main/java/io/zipcoder/interfaces/Students.java
index 47366bce..579e9751 100644
--- a/src/main/java/io/zipcoder/interfaces/Students.java
+++ b/src/main/java/io/zipcoder/interfaces/Students.java
@@ -1,16 +1,16 @@
package io.zipcoder.interfaces;
-public final class Students extends People{
+public final class Students extends People{
- private static final Students INSTANCE= new Students();
+ private static final Students INSTANCE = new Students();
private Students(){
super.add(new Student(05, "Ban"));
super.add(new Student(06, "chod"));
}
- public Student[] getStudentArray(){
- return new Student[0];
+ public Person[] toArray() {
+ return new Person[0];
}
public static Students getInstance(){
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..f0587ea0
--- /dev/null
+++ b/src/main/java/io/zipcoder/interfaces/ZipCodeWilmington.java
@@ -0,0 +1,30 @@
+package io.zipcoder.interfaces;
+
+public final class ZipCodeWilmington extends People{
+
+ private static final ZipCodeWilmington INSTANCE = new ZipCodeWilmington();
+ private static final Students students = Students.getInstance();
+ private static final Instructors instructors = Instructors.getInstance();
+
+ public void hostLecture(Teacher teacher, double numberOfHours){
+ teacher.lecture((Learner[]) students.toArray(),numberOfHours);
+ }
+
+ public void hostLecture(Long id, double numberOfHours){
+ Instructor instructor = instructors.findById(id);
+ instructor.lecture((Learner[]) students.toArray(),numberOfHours);
+ }
+
+ public static ZipCodeWilmington getInstance(){
+ if(INSTANCE != null){
+ return INSTANCE;
+ }
+ else{
+ return INSTANCE;
+ }
+ }
+
+ public Person[] toArray() {
+ return new Person[0];
+ }
+}
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..f288889b
--- /dev/null
+++ b/src/test/java/io/zipcoder/interfaces/TestInstructors.java
@@ -0,0 +1,21 @@
+package io.zipcoder.interfaces;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestInstructors {
+
+
+ @Test
+ public void test1(){
+ Person actualInstructor = null;
+ Long[] instructorArray = {0L, 1L};
+ Instructors actual = Instructors.getInstance();
+
+ for (int i = 0; i < instructorArray.length; i++) {
+ actualInstructor = actual.findById(instructorArray[i]);
+ }
+ Assert.assertTrue(actualInstructor != null);
+ }
+
+}
diff --git a/src/test/java/io/zipcoder/interfaces/TestStudents.java b/src/test/java/io/zipcoder/interfaces/TestStudents.java
index eef34b30..4bb3ae08 100644
--- a/src/test/java/io/zipcoder/interfaces/TestStudents.java
+++ b/src/test/java/io/zipcoder/interfaces/TestStudents.java
@@ -7,16 +7,15 @@ public class TestStudents {
@Test
public void test1(){
+ Person actualStudent = null;
Long [] studentArray = {5L, 6L};
Students actual = Students.getInstance();
for (int i = 0; i < studentArray.length; i++) {
- Person actualStudent = actual.findById(studentArray[i]);
+ actualStudent = actual.findById(studentArray[i]);
}
- Assert.assertTrue(actual != null);
-
-
+ Assert.assertTrue(actualStudent != null);
}
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..ea299120
--- /dev/null
+++ b/src/test/java/io/zipcoder/interfaces/TestZipCodeWilmington.java
@@ -0,0 +1,24 @@
+package io.zipcoder.interfaces;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestZipCodeWilmington {
+
+ @Test
+ public void testHostLecture(){
+ ZipCodeWilmington zcw = ZipCodeWilmington.getInstance();
+ Students students = Students.getInstance();
+ Instructors instructors = Instructors.getInstance();
+
+ zcw.hostLecture(instructors.findById(11L),3);
+
+ Student student1 = new Student;
+ Assert.assertEquals(3, student1.getTotalStudyTime());
+
+ }
+
+
+}
+
+
From 29187574ac7738a46ecea6fda8141235b850fc6b Mon Sep 17 00:00:00 2001
From: John Tokhi <56596400+tokhij@users.noreply.github.com>
Date: Mon, 25 Nov 2019 22:17:51 -0500
Subject: [PATCH 6/6] DONE LABBBBBBBBBB
---
.../java/io/zipcoder/interfaces/Educator.java | 26 +++++++
.../io/zipcoder/interfaces/Instructors.java | 4 +-
.../java/io/zipcoder/interfaces/Students.java | 4 +-
.../interfaces/ZipCodeWilmington.java | 8 +-
.../io/zipcoder/interfaces/TestEducator.java | 76 +++++++++++++++++++
.../io/zipcoder/interfaces/TestPeople.java | 6 +-
.../interfaces/TestZipCodeWilmington.java | 5 +-
7 files changed, 119 insertions(+), 10 deletions(-)
create mode 100644 src/main/java/io/zipcoder/interfaces/Educator.java
create mode 100644 src/test/java/io/zipcoder/interfaces/TestEducator.java
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..7c991537
--- /dev/null
+++ b/src/main/java/io/zipcoder/interfaces/Educator.java
@@ -0,0 +1,26 @@
+package io.zipcoder.interfaces;
+
+public enum Educator implements Teacher {
+ ZAN(0,"Zan"), ISANNOYING(1, "is Annoying");
+
+ public double timeWorked;
+ public final Instructor instructor;
+
+ Educator(long id, String name) {
+ instructor = new Instructor(id, name);
+ }
+
+ public void teach(Learner learner, double numberOfHours) {
+ this.timeWorked += numberOfHours;
+ instructor.teach(learner,numberOfHours);
+ }
+
+ public void lecture(Learner[] learners, double numberOfHours) {
+ this.timeWorked += numberOfHours;
+ instructor.lecture(learners,numberOfHours);
+ }
+
+ public double getTimeWorked(){
+ return timeWorked;
+ }
+}
diff --git a/src/main/java/io/zipcoder/interfaces/Instructors.java b/src/main/java/io/zipcoder/interfaces/Instructors.java
index 28c4382f..bce6775d 100644
--- a/src/main/java/io/zipcoder/interfaces/Instructors.java
+++ b/src/main/java/io/zipcoder/interfaces/Instructors.java
@@ -9,7 +9,7 @@ public final class Instructors extends People{
private Instructors(){
ArrayList instructorZan = new ArrayList();
instructorZan.add(0,"ZANN");
- instructorZan.add(1,"is Annoying");
+ instructorZan.add(1,"isAnnoying");
for (int i = 0; i < instructorZan.size(); i++) {
super.add(new Instructor(i,instructorZan.get(i)));
@@ -17,7 +17,7 @@ private Instructors(){
}
public Instructor[] toArray() {
- return new Instructor[0];
+ return personList.toArray(new Instructor[personList.size()]);
}
public static Instructors getInstance(){
diff --git a/src/main/java/io/zipcoder/interfaces/Students.java b/src/main/java/io/zipcoder/interfaces/Students.java
index 579e9751..5ab98eac 100644
--- a/src/main/java/io/zipcoder/interfaces/Students.java
+++ b/src/main/java/io/zipcoder/interfaces/Students.java
@@ -9,8 +9,8 @@ private Students(){
super.add(new Student(06, "chod"));
}
- public Person[] toArray() {
- return new Person[0];
+ public Student[] toArray() {
+ return personList.toArray(new Student[personList.size()]);
}
public static Students getInstance(){
diff --git a/src/main/java/io/zipcoder/interfaces/ZipCodeWilmington.java b/src/main/java/io/zipcoder/interfaces/ZipCodeWilmington.java
index f0587ea0..6fb1d95c 100644
--- a/src/main/java/io/zipcoder/interfaces/ZipCodeWilmington.java
+++ b/src/main/java/io/zipcoder/interfaces/ZipCodeWilmington.java
@@ -6,13 +6,17 @@ public final class ZipCodeWilmington extends People{
private static final Students students = Students.getInstance();
private static final Instructors instructors = Instructors.getInstance();
+ private ZipCodeWilmington(){
+
+ }
+
public void hostLecture(Teacher teacher, double numberOfHours){
- teacher.lecture((Learner[]) students.toArray(),numberOfHours);
+ teacher.lecture(students.toArray(),numberOfHours);
}
public void hostLecture(Long id, double numberOfHours){
Instructor instructor = instructors.findById(id);
- instructor.lecture((Learner[]) students.toArray(),numberOfHours);
+ instructor.lecture(students.toArray(),numberOfHours);
}
public static ZipCodeWilmington getInstance(){
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..60b2e1e1
--- /dev/null
+++ b/src/test/java/io/zipcoder/interfaces/TestEducator.java
@@ -0,0 +1,76 @@
+package io.zipcoder.interfaces;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestEducator {
+ Educator educator = Educator.ZAN;
+ Instructor instructor;
+ Student student;
+
+ @Before
+ public void testCon(){
+ instructor = new Instructor(11, "Zan");
+ student = new Student(01, "Johnny");
+ }
+
+ @Test
+ public void getTimeWorked(){
+ educator.teach(student, 5);
+
+ Double expected = 5.0;
+ Double actual = student.getTotalStudyTime();
+
+ Assert.assertEquals(expected,actual);
+
+
+ }
+
+ @Test
+ public void testImplementation(){
+ boolean instructorIsTeacher;
+ if(instructor instanceof Teacher){
+ instructorIsTeacher = true;
+ }
+ else{
+ instructorIsTeacher = false;
+ }
+ Assert.assertTrue(instructorIsTeacher);
+ }
+
+ @Test
+ public void testInheritance(){
+ boolean instructorIsTeacher;
+ if(instructor instanceof Teacher){
+ instructorIsTeacher = true;
+ }
+ else{
+ instructorIsTeacher = false;
+ }
+ Assert.assertTrue(instructorIsTeacher);
+ }
+
+ @Test
+ public void testTeach(){
+ instructor.teach(student, 3);
+
+ Double expectedTime = 3.0;
+ Double actualTime = student.getTotalStudyTime();
+
+ Assert.assertEquals(expectedTime, actualTime);
+ }
+
+ @Test
+ public void testLecture(){
+ Learner[] learners = {student};
+ instructor.lecture(learners,6);
+
+ Double expected = 6.0;
+ Double actual = student.getTotalStudyTime();
+
+ Assert.assertEquals(expected, actual);
+ }
+
+
+}
diff --git a/src/test/java/io/zipcoder/interfaces/TestPeople.java b/src/test/java/io/zipcoder/interfaces/TestPeople.java
index 2c3e60c5..1e8b8a80 100644
--- a/src/test/java/io/zipcoder/interfaces/TestPeople.java
+++ b/src/test/java/io/zipcoder/interfaces/TestPeople.java
@@ -13,7 +13,11 @@ public class TestPeople {
@Before
public void testContr(){
- peopleObject = new People();
+ peopleObject = new People() {
+ public Person[] toArray() {
+ return new Person[0];
+ }
+ };
person = new Person(11, "Zan");
person2 = new Person(01, "Johnny");
person3 = new Person(02, "Elliot");
diff --git a/src/test/java/io/zipcoder/interfaces/TestZipCodeWilmington.java b/src/test/java/io/zipcoder/interfaces/TestZipCodeWilmington.java
index ea299120..d4ea26e6 100644
--- a/src/test/java/io/zipcoder/interfaces/TestZipCodeWilmington.java
+++ b/src/test/java/io/zipcoder/interfaces/TestZipCodeWilmington.java
@@ -11,10 +11,9 @@ public void testHostLecture(){
Students students = Students.getInstance();
Instructors instructors = Instructors.getInstance();
- zcw.hostLecture(instructors.findById(11L),3);
+ zcw.hostLecture(Educator.ZAN,3);
- Student student1 = new Student;
- Assert.assertEquals(3, student1.getTotalStudyTime());
+ Assert.assertEquals(3, Educator.ZAN.getTimeWorked(),0);
}