Skip to content

Complete #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/libraries/Maven__junit_junit_4_12.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions interfaces-1.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
</component>
</module>
31 changes: 31 additions & 0 deletions src/main/java/io/zipcoder/interfaces/Educator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.zipcoder.interfaces;

public enum Educator implements Teacher {
KRIS(new Instructor(35, "Kris"),0),
ROBERTO(new Instructor(36, "Roberto"),0),
CHRIS(new Instructor(37, "Chris"),0);

private final Instructor instructor;
double timeWorked;

Educator(Instructor instructor, double timeWorked){
this.instructor = instructor;
this.timeWorked = timeWorked;
Instructors instructors = Instructors.getInstance();
instructors.addPerson(instructor);
}

public void teach(Learner learner, double numberOfHours) {
this.instructor.teach(learner,numberOfHours);
timeWorked += numberOfHours;
}

public void lecture(Learner[]learners, double numberOfHours) {
this.instructor.lecture(learners,numberOfHours);
timeWorked += numberOfHours;
}

public double getTimeWorked() {
return timeWorked;
}
}
22 changes: 22 additions & 0 deletions src/main/java/io/zipcoder/interfaces/Instructor.java
Original file line number Diff line number Diff line change
@@ -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);
}
}

}
24 changes: 24 additions & 0 deletions src/main/java/io/zipcoder/interfaces/Instructors.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.zipcoder.interfaces;

public final class Instructors extends People<Instructor> {
private static final Instructors INSTANCE = new Instructors();

private Instructors() {

Instructor instructor = new Instructor(35, "Kris");
Instructor instructor1 = new Instructor(36, "Roberto");
Instructor instructor2 = new Instructor(37, "Chris");

personList.add(instructor);
personList.add(instructor1);
personList.add(instructor2);
}

public Instructor[] toArray() {
return personList.toArray(new Instructor[personList.size()]);
}

public static Instructors getInstance(){
return INSTANCE;
}
}
10 changes: 10 additions & 0 deletions src/main/java/io/zipcoder/interfaces/Learner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.zipcoder.interfaces;

public interface Learner {


void learn(double numberOfHours);
double getTotalStudyTime();

}

58 changes: 58 additions & 0 deletions src/main/java/io/zipcoder/interfaces/People.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package io.zipcoder.interfaces;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public abstract class People<E extends Person> implements Iterable<E> {

List<E> personList;

public People(){
personList= new ArrayList<E>();
}

public void addPerson(E person){
personList.add(person);
}

public Person findById(Long id){
Person personFinder = null;
for (int i = 0; i < personList.size(); i++) {
if (personList.get(i).getId()==id){
personFinder = personList.get(i);
}
}return personFinder;
}

public Boolean contains(E person){
return personList.contains(person);
}

public void removePerson(E 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(personList.get(i));
}
}
}
public void removeAll(){
personList.removeAll(personList);
}

public int count(){
return personList.size();
}

public abstract E[] toArray();



public Iterator<E> iterator() {
return personList.iterator();
}
}
24 changes: 24 additions & 0 deletions src/main/java/io/zipcoder/interfaces/Person.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
package io.zipcoder.interfaces;

public class Person {
final Long id;
private String name;


public Person(long id, String name) {
this.name = name;
this.id = id;
}
public Long getId() {
return id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}





}

22 changes: 22 additions & 0 deletions src/main/java/io/zipcoder/interfaces/Student.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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;
}

public double getTotalStudyTime() {
return totalStudyTime;
}


}
27 changes: 27 additions & 0 deletions src/main/java/io/zipcoder/interfaces/Students.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.zipcoder.interfaces;

public final class Students extends People<Student> {
private static final Students INSTANCE = new Students();

private Students() {
Student student = new Student(25, "Sandy");
Student student1 = new Student(26, "Meeeee");
Student student2 = new Student(27, "Kievina");

personList.add(student);
personList.add(student1);
personList.add(student2);
}

public Student[] toArray() {
return personList.toArray(new Student[personList.size()]);
}

public static Students getInstance() {
return INSTANCE;
}



}

7 changes: 7 additions & 0 deletions src/main/java/io/zipcoder/interfaces/Teacher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.zipcoder.interfaces;

public interface Teacher {
void teach(Learner learner, double numberOfHours);
void lecture(Learner[]learners,double numberOfHours);

}
41 changes: 41 additions & 0 deletions src/main/java/io/zipcoder/interfaces/ZipCodeWilmington.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.zipcoder.interfaces;

import java.util.HashMap;
import java.util.Map;

public final class ZipCodeWilmington {
private static final ZipCodeWilmington INSTANCE = new ZipCodeWilmington();
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(students.toArray(), numberOfHours);
}

public void hostLecture(long id, double numberOfHours) {
Teacher teacher = (Instructor) instructors.findById(id);
teacher.lecture(students.toArray(), numberOfHours);


}

public Map getStudyMap() {
Map<Student, Double> timeMap = new HashMap<Student, Double>();

for (Student s : students) {
timeMap.put(s, s.getTotalStudyTime());
}
return timeMap;
}

public static ZipCodeWilmington getInstance() {
return INSTANCE;
}


}
Loading