Skip to content

Dev #71

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 6 commits into
base: master
Choose a base branch
from
Open

Dev #71

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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.classpath
#.project
.settings
*.idea/
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>
35 changes: 35 additions & 0 deletions src/main/java/io/zipcoder/interfaces/Educator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.zipcoder.interfaces;

public enum Educator implements Teacher {
SAM,
NICK,
FRANK,
CHRIS;

private final Instructor instructor;
private Double timeWorked = 0.0;

Educator() {

this.instructor = new Instructor((long) ordinal(), name());

}


public Double timeWorked() {

return timeWorked;
}

public void teach(Learner learner, double numberOfHours) {

timeWorked += numberOfHours;
this.instructor.teach(learner, numberOfHours);
}

public void lecture(Learner[] learners, double numberOfHours) {

timeWorked += numberOfHours;
this.instructor.lecture(learners, numberOfHours);
}
}
26 changes: 26 additions & 0 deletions src/main/java/io/zipcoder/interfaces/Instructor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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 hoursPerStudent = numberOfHours / learners.length;

for(Learner learner : learners)
learner.learn(hoursPerStudent);

}

}

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

public final class Instructors extends People<Instructor>{

private static final Instructors INSTANCE = new Instructors();

private Instructors(){

Instructor newInstructor1 = new Instructor(100L, "Rick");
Instructor newInstructor2 = new Instructor(110L, "Dana");
Instructor newInstructor3 = new Instructor(120L, "John");

super.add(newInstructor1);
super.add(newInstructor2);
super.add(newInstructor3);

}

public Instructor[] getArray() {
return super.personList.toArray(new Instructor[0]);
}

public static Instructors getInstance(){

return INSTANCE;
}

}

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

public interface Learner {

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


}
60 changes: 60 additions & 0 deletions src/main/java/io/zipcoder/interfaces/People.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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 add(E person){

personList.add(person);
}

public E findById(long id){

for(E person : personList)
if(person.getId() == id)
return person;

return null;
}

public boolean contains(Person person){

return personList.contains(person);
}

public void removeByPerson(Person person){

personList.remove(person);
}

public void removeById(long id) {
personList.remove(findById(id));
}

public void removeAll(){

personList.clear();
}

public int count(){

return personList.size();
}

public abstract E[] getArray();

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

public class PeopleClass extends People<Person>{

public Person[] getArray() {
return personList.toArray(new Person[0]);

}
}
21 changes: 21 additions & 0 deletions src/main/java/io/zipcoder/interfaces/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,25 @@

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() {
return name;
}

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


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

public final class Students extends People<Student>{

private static final Students INSTANCE = new Students();

private Students(){

Student newStudent1 = new Student(10L, "Sam");
Student newStudent2 = new Student(20L, "Dan");

super.add(newStudent1);
super.add(newStudent2);

}

public Student[] getArray() {
return super.personList.toArray(new Student[0]);
}

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);
}
Loading