Skip to content
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

passed all tests #84

Open
wants to merge 1 commit 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.

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.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.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.

11 changes: 11 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_11">
<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>
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@
<groupId>io.zipcoder</groupId>
<artifactId>interfaces-1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
<packaging>jar</packaging>

<name>interfaces-1</name>
Expand Down
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 {
LEON (new Instructor(0, "Leon")),
DOLIO(new Instructor(1,"Dolio")),
KRIS(new Instructor(2,"Kris"));

private final Instructor instructor;
private Double timeWorked;

Educator(Instructor instructor) {
this.instructor = instructor;
Instructors.getInstance().add(instructor);
}

@Override
public void teach(Learner learner, Double numberOfHours) {
instructor.teach(learner,numberOfHours);
setTimeWorked(numberOfHours);
}

@Override
public void lecture(Learner[] learners, Double numberOfHours) {
instructor.lecture(learners,numberOfHours);
setTimeWorked(numberOfHours);
}

public void setTimeWorked(Double timeWorked) {
this.timeWorked = timeWorked;
}

public Double getTimeWorked() {
return timeWorked;
}
}
37 changes: 37 additions & 0 deletions src/main/java/io/zipcoder/interfaces/Instructor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.zipcoder.interfaces;

/**
* Create an Instructor class such that:
* Instructor is a subclass of Person
* Instructor implements the Teacher interface
*
* Instructor should have a concrete implementation of the teach method
* which invokes the learn method on the specified Learner object.
*
* Instructor should have a concrete implementation of the lecture method
* which invokes the learn method on each of the elements in the specified array of Learner objects.
*
* numberOfHours should be evenly split amongst the learners.
* double numberOfHoursPerLearner = numberOfHours / learners.length;
*/

public class Instructor extends Person implements Teacher {

public Instructor(long id, String name) {
super(id, name);
}


@Override
public void teach(Learner learner, Double numberOfHours) {
learner.learn(numberOfHours);
}

@Override
public void lecture(Learner[] learners, Double numberOfHours) {
Double numberOfHoursPerLearner = numberOfHours/ learners.length;
for(Learner learner: learners){
learner.learn(numberOfHoursPerLearner);
}
}
}
20 changes: 20 additions & 0 deletions src/main/java/io/zipcoder/interfaces/Instructors.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.zipcoder.interfaces;

import java.util.Arrays;

public final class Instructors extends People<Instructor> {
private final static Instructors INSTANCE = new Instructors();
private Instructors(){
Instructor leon = new Instructor(0,"Leon");
Instructor dolio = new Instructor(1,"Dolio");
Instructor kris = new Instructor(2, "Kris");
Arrays.asList(leon, dolio, kris).forEach(this::add);
}

@Override
public Instructor[] toArray() {
return INSTANCE.getPersonList().toArray(new Instructor[0]);
}

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

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

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

/**
* Create a People class.
* The class should instantiate a List field of Person objects named personList.
* The class should define a method named add which adds a Person to the personList.
* The class should define a method named findById which makes use of a long id parameter
* to return a Person object with the respective id field.
* The class should define a method named contains which makes use of a Person person parameter to
* return true if the personList contains the respective Person object.
* The class should define a method named remove which makes use of a Person person parameter
* to remove a respective Person object.
* The class should define a method named remove which makes use of a long id parameter to
* remove a Person object with the respective id field.
* The class should define a named removeAll which clears our personList field.
* The class should define a method named count which returns the size of personList.
* The class should define a method named toArray which returns an array representation of the
* personList field.
*
* The class should implement Iterable<E> and define a method named iterator which makes use of
* the personList field to generate a new a Iterator<E>.
*
*/
public abstract class People<PersonType extends Person> implements Iterable<PersonType> {
private List<PersonType> personList;

public People() {
this.personList = new ArrayList<PersonType>();
}

public void add(PersonType person){
personList.add(person);
}

public PersonType findById(long id){
for(PersonType person:personList){
if(person.getId() == id){
return person;
}
}
return null;
}

public boolean contains(PersonType person){
if(personList.contains(person)){
return true;
}
return false;
}

//Should only remove - not return a string
public void removePerson(PersonType person){
if(personList.contains(person)){
personList.remove(person);
} else {
throw new UnsupportedOperationException("That person is not here");
}
}

public void removeById(long id){
personList.removeIf(person -> person.getId() == id);
}

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

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

public abstract PersonType[] toArray();

@Override
public Iterator iterator() {
return personList.iterator();
}

public List<PersonType> getPersonList() {
return personList;
}
}
19 changes: 19 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,23 @@

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

public class Student extends Person implements Learner{
private long id;
private String name;
private Double totalStudyTime;

public Student(long id, String name) {
super(id, name);
}

public Student() {
super(0,"");
}

@Override
public void learn(Double numberOfHours) {
this.totalStudyTime = numberOfHours;
}

@Override
public Double getTotalStudyTime() {
return this.totalStudyTime;
}

}
Loading