Skip to content

Learned a ton #88

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.

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
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 {
Leon(111L, "Leon"),
Dolio(112L, "Dolio"),
Kris(113L, "Kris");

final Instructor instructor;
double timeWorked;

Educator(Long id, String name) {
instructor = new Instructor(id, name);
Instructors.getInstance().add(instructor);
}


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

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

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 (int i = 0; i < learners.length; i++) {
// learners[i].learn(numberOfHoursPerLearner);

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

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

public class Instructors extends People<Instructor> {

private static final Instructors INSTANCE = new Instructors();

private Instructors() {
add(new Instructor(111L,"Leon"));
add(new Instructor(112L,"Dolio"));
add(new Instructor(113L,"Kris"));
}

public static Instructors getInstance() {
return INSTANCE;
}


@Override
public Instructor[] toArray() {
return personList.toArray(new Instructor[0]);
}
}
8 changes: 8 additions & 0 deletions src/main/java/io/zipcoder/interfaces/Learner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.zipcoder.interfaces;

public interface Learner {

void learn(double numberOfHours);

Double getTotalStudyTime();
}
62 changes: 62 additions & 0 deletions src/main/java/io/zipcoder/interfaces/People.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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){
if (person.getId() == (id)) {
return person;
}
}
return null;
}

public Boolean contains(Person person) {
//if (personList.contains(person)) {
for( Person person1 : personList) {
if (person1.getName() == person.name
&& person1.getId() == person.id) {
return true;
}
}
return false;
}

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

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

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

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

public abstract E[] toArray();


@Override
public Iterator<E> iterator() {
Iterator iteratorList = personList.iterator();
return iteratorList;
}
}
19 changes: 19 additions & 0 deletions src/main/java/io/zipcoder/interfaces/Person.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
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 id;
}

public String getName() {
return name;
}

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

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

public class Student extends Person implements Learner {

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

double totalStudyTime;


@Override
public void learn(double numberOfHours) {
totalStudyTime = totalStudyTime + numberOfHours;
}

@Override
public Double getTotalStudyTime() {
return totalStudyTime;
}
}
43 changes: 43 additions & 0 deletions src/main/java/io/zipcoder/interfaces/Students.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.zipcoder.interfaces;

public class Students extends People<Student> {

private static final Students INSTANCE = new Students();

private Students(){
add(new Student(122L, "Manny"));
add(new Student(123L, "ZachK"));
add(new Student(124L, "Rex"));
add(new Student(125L, "Nisha"));
add(new Student(126L, "Bobbi"));
add(new Student(127L, "Aidan"));
add(new Student(128L, "Charnae"));
add(new Student(129L, "Chuck"));
add(new Student(130L, "Dee"));
add(new Student(131L, "Dipinti"));
add(new Student(132L, "Jen"));
add(new Student(133L, "Jeremy"));
add(new Student(134L, "John"));
add(new Student(135L, "ZachS"));
add(new Student(136L, "Laura"));
add(new Student(137L, "Nathan"));
add(new Student(138L, "Nikki"));
add(new Student(139L, "Raymond"));
add(new Student(140L, "Sean"));
add(new Student(141L, "Sitara"));
add(new Student(142L, "Tatiana"));
add(new Student(143L, "Wesley"));

}


public static Students getInstance(){
return INSTANCE;
}


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