Skip to content

Learned Lots Lengthy Learner Lab #85

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
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_14">
<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>14</source>
<target>14</target>
</configuration>
</plugin>
</plugins>
</build>
<packaging>jar</packaging>

<name>interfaces-1</name>
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/io/zipcoder/interfaces/Educator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.zipcoder.interfaces;

public enum Educator implements Teacher{
LEON (new Instructor(76L, "Leon")),
DOLIO (new Instructor(70L, "Dolio")),
KRIS (new Instructor(72L, "Kris"));

private final Instructor instructor;
private double timeWorked;

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

public Instructor getInstructor(){
return instructor;
}

public Double getTimeWorked(){
return timeWorked;
}

@Override
public void teach(Learner learner, Double numberOfHours) {
this.timeWorked += numberOfHours;
learner.learn(numberOfHours);

}

@Override
public void lecture(Learner[] learners, Double numberOfHours) {
this.timeWorked += numberOfHours;
double hoursLearned = numberOfHours/ learners.length;
for (Learner learner : learners) {
learner.learn(hoursLearned);
}
}

}
25 changes: 25 additions & 0 deletions src/main/java/io/zipcoder/interfaces/Instructor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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 hoursPerLearner = numberOfHours/ learners.length;

for (Learner learner : learners) {
learner.learn(hoursPerLearner);
}

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

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

private Instructors (){
this.add(new Instructor(444L, "Dolio"));
this.add(new Instructor(445L, "Leon"));
this.add(new Instructor(446L, "Kris"));
}

public static Instructors getInstance(){
return INSTANCE;
}

public Instructor[] getArray(){
return personList.toArray(new Instructor[0]);
}
}
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();
}
48 changes: 48 additions & 0 deletions src/main/java/io/zipcoder/interfaces/People.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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 = new ArrayList<>();

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

public E findById(Long id){
for (E person : personList) {
Long currentId = person.getId();
boolean isSameId = currentId.equals(id);
if (isSameId)
return person;
}
return null;
}

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

public void removeById(Long id){
personList.removeIf(person -> person.getId().equals(id));

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

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

public abstract E[] getArray();

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

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

import java.util.Objects;

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

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

public String getName() {
return name;
}

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

public Long getId() {
return id;
}

@Override
public String toString() {
return "Person{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}

@Override
public boolean equals(Object o){
return o.toString().equals(toString());
}
}
20 changes: 20 additions & 0 deletions src/main/java/io/zipcoder/interfaces/Student.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.zipcoder.interfaces;

public class Student extends Person implements Learner{

Double totalStudyTime = 0.0;

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


public void learn(Double hours){
totalStudyTime += hours;
}

public Double getTotalStudyTime(){
return totalStudyTime;
}
}

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

import java.util.ArrayList;

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

private Students() {
this.add(new Student(644L, "Nick"));
this.add(new Student(645L, "Char"));
this.add(new Student(646L, "Sitara"));
this.add(new Student(647L, "Zach"));
this.add(new Student(648L, "Dipinti"));
this.add(new Student(649L, "Jeremy"));
this.add(new Student(650L, "Tatiana"));
this.add(new Student(651L, "Ray"));
this.add(new Student(652L, "Nisha"));
this.add(new Student(653L, "Manny"));
this.add(new Student(654L, "Nathan"));
this.add(new Student(655L, "Laura"));
this.add(new Student(656L, "Jen"));
this.add(new Student(657L, "Zachary"));
this.add(new Student(658L, "John"));
this.add(new Student(659L, "Bobbi"));
this.add(new Student(660L, "Rex"));

}

public static Students getInstance() {
return INSTANCE;
}

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