Skip to content

finished lab #70

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 4 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
19 changes: 19 additions & 0 deletions .idea/$PRODUCT_WORKSPACE_FILE$

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

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

public enum Educator implements Teacher{
DOLIO(new Instructor(311412L, "Dolio")),
ROBERTO(new Instructor(24302L, "Roberto"));

final 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;
}
}
21 changes: 21 additions & 0 deletions src/main/java/io/zipcoder/interfaces/Instructor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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 numberofHoursPerStudent = numberOfHours / learners.length;
for(Learner learner : learners)
learner.learn(numberofHoursPerStudent);
}



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

public final class Instructors extends People<Instructor>{

private static final Instructors INSTANCE = new Instructors();



private Instructors(){
super();
Instructor instructorOne = new Instructor(311412L, "Dolio");
Instructor instructorTwo = new Instructor(24302L, "Roberto");

personList.add(instructorOne);
personList.add(instructorTwo);

}

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

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

public interface Learner {

void learn(double numberOfHours);
Double getTotalStudyTime();
}
52 changes: 52 additions & 0 deletions src/main/java/io/zipcoder/interfaces/People.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package io.zipcoder.interfaces;

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

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(E person){
return personList.contains(person);
}

public void removeByPerson(E person){
personList.remove(person);
}

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

public void removeAll(){
personList.clear();
}

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

abstract E[] getArray();

public Iterator<E> iterator() {
return personList.iterator();
}
}
18 changes: 18 additions & 0 deletions src/main/java/io/zipcoder/interfaces/Person.java
Original file line number Diff line number Diff line change
@@ -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 this.id;
}

public String getName(){
return this.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;
}
}
26 changes: 26 additions & 0 deletions src/main/java/io/zipcoder/interfaces/Students.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.zipcoder.interfaces;

public final class Students extends People<Student>{

private static final Students INSTANCE = new Students();

private Students(){

Student studentOne = new Student(212242L, "Brian");
Student studentTwo = new Student(121231L, "Kievina");

personList.add(studentOne);
personList.add(studentTwo);

}

@Override
public Student[] getArray(){

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

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

public interface Teacher {

void teach(Learner learner, double numberOfHours);
void lecture(Learner[] learner, double numberOfHours);


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

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

public final class ZipCodeWilmington {

private final Students students = Students.getInstance();
private final Instructors instructors = Instructors.getInstance();
private static final ZipCodeWilmington INSTANCE = new ZipCodeWilmington();

private ZipCodeWilmington(){
}

public void hostLecture(Teacher teacher, double numberOfHours){
teacher.lecture(students.getArray(), numberOfHours);
}

public void hostLecture(long id, double numberOfHours){
Teacher teacher = (Teacher) instructors.findById(id);
hostLecture(teacher, numberOfHours);
}

public HashMap<Student, Double> getStudyMap(){
HashMap<Student, Double> studyMap = new HashMap<Student, Double>();
for(Person person : students.getArray()){
Student student = (Student) person;
studyMap.put(student, student.getTotalStudyTime());
}
return studyMap;
}

public static ZipCodeWilmington getInstance(){
return INSTANCE;
}


}
Loading