Skip to content
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
36 changes: 36 additions & 0 deletions src/main/java/com/github/curriculeon/Classroom.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.github.curriculeon;

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

public class Classroom {
Students students;
Instructors instructors;

public Classroom(){
this(Students.getINSTANCE(),Instructors.getINSTANCE());
}

public Classroom(Students students, Instructors instructors) {
this.students = students;
this.instructors = instructors;

}

public void hostLecture(Teacher teacher, double numOfHours){
teacher.lecture(students.toArray(),numOfHours);
}

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

public Map<Student,Double> getStudyMap(){
Map<Student,Double> tempMapping = new HashMap<Student,Double>();
Student[] tempStudents = new Student[students.count()];
tempStudents = students.toArray();
for (Student student: tempStudents)
tempMapping.put(student,student.getTotalStudyTime());
return tempMapping;
}
}
39 changes: 39 additions & 0 deletions src/main/java/com/github/curriculeon/Educator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.github.curriculeon;

public enum Educator implements Teacher{
Leon(0.0),
Haseeb(0.0);
private final long id;
private final String name;
private final Instructor teacher;
private double timeWorked = 0;

Educator(double timeWorked) {
this.id = this.ordinal();
this.name = this.name();
teacher = new Instructor(id,name);
}

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

@Override
public void lecture(Learner[] learners, double numberOfHours) {
this.teacher.lecture(learners,numberOfHours);
}

public double getTimeWorked() {
return timeWorked;
}

public String getName() {
return name;
}

public long getId() {
return id;
}
}
20 changes: 20 additions & 0 deletions src/main/java/com/github/curriculeon/Instructor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.github.curriculeon;

public class Instructor extends Person implements Teacher {
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){
this.teach(learner,numberOfHoursPerLearner);
}
}
}
33 changes: 33 additions & 0 deletions src/main/java/com/github/curriculeon/Instructors.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.github.curriculeon;

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

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

private Instructors(){
final Instructor leon = new Instructor(Educator.Leon.getId(),Educator.Leon.getName());
final Instructor haseeb = new Instructor(Educator.Haseeb.getId(),Educator.Haseeb.getName());
this.add(leon);
this.add(haseeb);
}

public static Instructors getINSTANCE() {
return INSTANCE;
}

@Override
public Instructor[] toArray() {
Instructor[] tempArray = new Instructor[this.instructors.count()];
int i = 0;
for (Instructor instructor : this) {
tempArray[i] = instructor;
i++;
}
return tempArray ;
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/github/curriculeon/Learner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.github.curriculeon;

public interface Learner {
long getId();
String getName();
void learn(double numberOfHours);
Double getTotalStudyTime();
void setName(String name);

}
68 changes: 68 additions & 0 deletions src/main/java/com/github/curriculeon/People.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.github.curriculeon;

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

public abstract class People <PersonType extends Person> implements Iterable<PersonType> {
private final List<PersonType> personList;

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

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


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

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

public void remove(long id){
for(PersonType person: personList){
if(person.getId() == id) {
personList.remove(person);
return;
}
}
}
public void removeAll(){
this.personList.clear();
}

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

public abstract PersonType[] toArray();

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









}
22 changes: 22 additions & 0 deletions src/main/java/com/github/curriculeon/Person.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
package com.github.curriculeon;

public class Person {
private final long id;
private String name;
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;
}





}
22 changes: 22 additions & 0 deletions src/main/java/com/github/curriculeon/Student.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.github.curriculeon;

public class Student extends Person implements Learner {
private double totalStudyTime;

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

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

}

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

}

35 changes: 35 additions & 0 deletions src/main/java/com/github/curriculeon/Students.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.github.curriculeon;

import java.util.ArrayList;
import java.util.List;
import java.util.Spliterator;
import java.util.function.Consumer;

public final class Students extends People<Student> {

final static Students INSTANCE = new Students();
private Students(){
Student student1 = new Student(1, "Marcus");
Student student2 = new Student(2, "Yuru");
Student student3 = new Student(3,"David");
this.add(student1);
this.add(student2);
this.add(student3);
}

public static Students getINSTANCE() {
return INSTANCE;
}

@Override
public Student[] toArray() {
Student[] tempArray = new Student[this.count()];
int i = 0;
for (Student student : this) {
tempArray[i] = student;
i++;
}
return tempArray ;
}

}
6 changes: 6 additions & 0 deletions src/main/java/com/github/curriculeon/Teacher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.github.curriculeon;

public interface Teacher {
void teach(Learner learner, double numberOfHours);
void lecture(Learner[] learners, double numberOfHours);
}
23 changes: 23 additions & 0 deletions src/test/java/com/github/curriculeon/TestClassroom.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.github.curriculeon;

import org.junit.Assert;
import org.junit.Test;

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

public class TestClassroom {

@Test
public void testHostLecture(){
Classroom classroom = new Classroom();
Instructor leon = new Instructor(1, "Leon");
classroom.hostLecture(leon,9);
Student student = classroom.students.findById(1);
double expected = 3;
Map<Student,Double> tempMap = classroom.getStudyMap();
double actual = tempMap.get(student);
Assert.assertEquals(actual,expected,0.0);

}
}
17 changes: 17 additions & 0 deletions src/test/java/com/github/curriculeon/TestEducator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.github.curriculeon;

import org.junit.Assert;
import org.junit.Test;

public class TestEducator {

@Test
public void testConstructor(){
Instructors instructors = Instructors.getINSTANCE();
Educator educator = Educator.Haseeb;
double actual = educator.getTimeWorked();
Assert.assertEquals(actual,0.0,0.0);


}
}
Loading