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

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

// Create a Classroom singleton.
public enum Classroom {
INSTANCE;
// The class should declare a field that references the instance of Students called students.
private Students students = Students.getInstance();
// The class should declare a field that references the instance of Instructors called instructors.
private Instructors instructors = Instructors.getInstance();

// The class should define a method hostLecture
// which makes use of a Teacher teacher, double numberOfHours parameter
// to host a lecture to the composite personList field in the students reference.
public void hostLecture(Teacher teacher, Double numberOfHours) {
teacher.lecture(students.toArray(), numberOfHours);
}
// The class should define a method hostLecture
// which makes use of a long id, double numberOfHours parameter
// to identify a respective Instructor to host a lecture to the composite personList field in the cohort reference.
public void hostLecture(long id, double numberOfHours) {
Teacher instructor = instructors.findById(id);
instructor.lecture(students.toArray(), numberOfHours);
}
// The class should define a method getStudyMap
// which returns a new instance of a mapping from Student objects to Double objects,
// representative of each respective student's totalStudyTime.
public Map<Student, Double> getStudyMap() {
Map<Student, Double> result = new HashMap<>();
for(Student student : students.toArray()) {
Double studyTime = student.getTotalStudyTime();
result.put(student, studyTime);
}
return result;
}
}
32 changes: 32 additions & 0 deletions src/main/java/com/github/curriculeon/Educator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.github.curriculeon;

public enum Educator implements Teacher {
LEON,
HASEEB;
private Double hoursWorked;
private final Instructor instructor;

Educator() {
long id = this.ordinal(); //inherited from 'Enum' implicit super class
String name = this.name(); //inherited from 'Enum' implicit super class
this.instructor = new Instructor(id, name);
Instructors.getInstance().add(instructor);
}
@Override
public void teach(Learner learner, Double numberOfHours) {
instructor.teach(learner, numberOfHours);
hoursWorked += numberOfHours;
}
@Override
public void lecture(Learner[] learners, Double numberOfHours) {
instructor.lecture(learners, numberOfHours);
hoursWorked += numberOfHours;
}
}

/*Create an enum named Educator.
The enum should implement Teacher.
The enum should have an enumeration for each of the instructors represented in the Instructors class.
Upon construction each enumeration of the enum should instantiate a respective Instructor and assign it to a final instructor field upon construction. The instructor should be added to the Instructors singleton.
Calls to the teach and lecture method should be deferred to the composite instructor reference.
The enum should have a double timeWorked field which keeps track of the hours that the Educator has taught.*/
38 changes: 38 additions & 0 deletions src/main/java/com/github/curriculeon/Instructor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.github.curriculeon;


// Create an Instructor class such that:
//Instructor is a subclass of Person
//Instructor implements the Teacher interface
public class Instructor extends Person implements Teacher {

// create 'Instructor' constructor
public Instructor(Long id, String name) {
super(id, name);
}

// Instructor should have a concrete implementation of the teach method
// which invokes the learn method on the specified Learner object.
@Override
public void teach(Learner learner, Double numberOfHours) {
learner.learn(numberOfHours);
}

//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;
@Override
public void lecture(Learner[] learners, Double numberOfHours) {
double numberOfHoursPerLearner = numberOfHours / learners.length;
for (int i = 0; i < learners.length; i++) {
Learner learner = learners[i];
learner.learn(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.List;

// Create a Instructors singleton which represents the set of instructors.
// Create a Instructors class.
// The class should be an unextendable subclass of the People class.
public class Instructors extends People<Instructor> {

// The class should statically instantiate a final field named INSTANCE of type Instructors.
private static final Instructors instance = new Instructors();

// The class should define a private nullary constructor
// which populates the INSTANCE field with respective Instructor representations of your colleagues.
public Instructors() {
this.add(new Instructor(0L, "Leon Hunter")); // Each instructor should have a relatively unique id field.
this.add(new Instructor(1L, "Haseeb Muhammad"));
}
@Override
public Instructor[] toArray() {
int sizeOfArray = count();
Instructor[] destinationArray = new Instructor[sizeOfArray];
List<Instructor> sourceList = personList;
return sourceList.toArray(destinationArray);
}
// The class should define a getInstance method which returns the INSTANCE field
public static Instructors getInstance() {
return instance;
}
}



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

//Create a Learner interface.
public interface Learner {
void learn(Double numberOfHours);
/*Learner should declare method signature:
/*Method name: learn
Method parameters: double numberOfHours
Method return-type: void
*/

/*Learner should declare method signature:
Method name: getTotalStudyTime
Method return-type: Double
*/
Double getTotalStudyTime();
}
86 changes: 86 additions & 0 deletions src/main/java/com/github/curriculeon/People.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.github.curriculeon;

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

//Create a People class
// The class should instantiate a List field of Person objects named personList.
abstract public class People <SomeLearnerType extends Person> implements Iterable<SomeLearnerType> {
List<SomeLearnerType> personList;

public People() {
this(new ArrayList<>());
}
// Create 'People' Constructor
public People(List<SomeLearnerType> personList) {
//set a List field of Person objects named personList to the respective value
this.personList = personList;
}

// The class should define a method named add which adds a Person to the personList.
public void add(SomeLearnerType person) {
this.personList.add(person);
}
// 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.
public SomeLearnerType findById(long id) {
for (int i = 0; i < personList.size(); i++) {
SomeLearnerType person = personList.get(i);
if (person.getId() == id) { //if the id is correct,
return person; // return person
} else { // if its the wrong id,
continue; // keep looking
}
} // finished loop; we've finished looking
return null; // we were not able to find the person with the id
}

// The class should define a named contains which makes use of a Person person parameter
// to return true if the personList contains the respective Person object.
public SomeLearnerType findByIdExpanded(long id) {
for (int i = 0; i < personList.size(); i++) {
SomeLearnerType person = personList.get(i);
if (person.getId() == id) { //if the id is correct,
return person; // return person
} else { // if its the wrong id,
continue; // keep looking
}
} // finished loop; we've finished looking
return null; // we were not able to find the person with the id
}
public Boolean contains(SomeLearnerType specifiedPerson) {
return personList.contains(specifiedPerson);
}
// The class should define a method named remove
// which makes use of a Person person parameter to remove a respective Person object.
public void remove(SomeLearnerType someSpecificPerson) {
personList.remove(someSpecificPerson);
}

// 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.
public void removeAll() {
personList.clear();
}
// The class should define a method named count
// which returns the size of personList.
public int count() {
return personList.size();
}

// The class should define a method named toArray
// which returns an array representation of the personList field.

abstract public SomeLearnerType[] toArray();
// 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>

@Override
public Iterator<SomeLearnerType> iterator() {
return personList.iterator();
}
}
26 changes: 25 additions & 1 deletion src/main/java/com/github/curriculeon/Person.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
package com.github.curriculeon;

//create a 'Person' class
public class Person {
private final Long id;//declare final field named 'id' of type 'long'
private String name;//declare a field named 'name' of type String

}
// create 'Person' constructor
public Person() {
this.id = null;
}
public Person(Long id, String name) { // with parameters of type long and String
//sets the id and name field to the respective values
this.id = id;
this.name = name;
}
//class should define a getId() method which returns the Person object's id field.
public Long getId() {
return id;
}
//define a getName() method which returns the Person object's name field.
public String getName() {
return name;
}
//define a setName() method which sets the Person object's name field.
public void setName(String name) {
this.name = name;
}
}
28 changes: 28 additions & 0 deletions src/main/java/com/github/curriculeon/Student.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.github.curriculeon;


//Create a Student class such that:
//Student is a subclass of Person
//Student implements the Learner interface
public class Student extends Person implements Learner {
//Student should have an instance variable totalStudyTime of type double
private double totalStudyTime;
//create 'Student' constructor
public Student(Long id, String name) {
//sets the id and name field to the respective values
super(id, name);
}

//Student should have a concrete implementation of the learn method
// which increments (+) the totalStudyTime variable by the specified numberOfHours argument.
@Override
public void learn(Double numberOfHours) {
this.totalStudyTime = totalStudyTime + numberOfHours;
}
//Student should have a getTotalStudyTime() method
// which returns the totalStudyTime instance variable.
@Override
public Double getTotalStudyTime() {
return totalStudyTime;
}
}
34 changes: 34 additions & 0 deletions src/main/java/com/github/curriculeon/Students.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.github.curriculeon;

import java.util.List;

// Students singleton - create a Students class.
//The class should be an unextendable subclass of the People class.
public class Students extends People<Student>{
// The class should statically instantiate a final field named INSTANCE of type Students.
private static final Students instance = new Students();

// The class should define a private nullary constructor
// which populates the INSTANCE field with respective Student representations of your colleagues.
//private constructor to avoid client applications to use constructor
private Students(){
super(); // optional invocation
this.add(new Student(0L, "Julia")); // Each student should have a relatively unique id field.
this.add(new Student(1L, "David Y"));
this.add(new Student(2L, "Ghasan"));
}
@Override
public Student[] toArray() {
int sizeOfArray = count();
Student[] destinationArray = new Student[sizeOfArray];
List<Student> sourceList = personList;
return sourceList.toArray(destinationArray);
}

// The class should define a getInstance method which returns the INSTANCE field
public static Students getInstance(){
return instance;
}
}


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

// Create a Teacher interface.
public interface Teacher {
/*Teacher should declare a teach method signature:
Method name: teach
Method parameters:
Learner learner
double numberOfHours
Method return-type: void
*/
void teach(Learner learner, Double numberOfHours);

/* Teacher should declare a lecture method signature:
Method name: lecture
Method parameters:
Learner[] learners
double numberOfHours
Method return-type: void
*/
void lecture(Learner[] learners, Double numberOfHours);
}
Loading