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
42 changes: 42 additions & 0 deletions src/main/java/com/github/curriculeon/Classroom.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.github.curriculeon;
/*
Create a Classroom singleton.
The class should declare a field that references the instance of Students called students. DONE
The class should declare a field that references the instance of Instructors called instructors. Done
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.Done
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. Done
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.

*/

import java.util.ArrayList;
import java.util.Map;
import java.util.TreeMap;

public class Classroom {
Students students = Students.getInstance();
Instructors instructors = Instructors.getInstance();

public void hostLecture(Teacher teacher, Double numberOfHours) {
teacher.lecture(students.toArray(), numberOfHours);
}

public void hostLecture(Long id, Double numberOfHours) {
instructors.findByID(id).lecture(students.toArray(), numberOfHours);
}

public Map<Long, Double> getStudyMap() {
Map<Long, Double> map = new TreeMap<>();
ArrayList<Student> slist = students.personList;
for (Student stu : slist) {
map.put(stu.getId(),stu.getTotalStudyTime());
}
return map;
}

}

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

public enum Educator implements Teacher {
LEON,
HASEEB;

private Double hoursWorked;
private final Instructor instructor;

@Override
public void teach(Learner learner, Double numberOfHours) {

}

@Override
public void lecture(Learner[] learners, Double numberOfHours) {

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

/*
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 {
Double numberOfHoursPerLearner =0.0;

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) {
this.numberOfHoursPerLearner += numberOfHours;
for (Learner learner : learners) {//I got this from Chris fulton
this.teach(learner, numberOfHours);
}
}
}
58 changes: 58 additions & 0 deletions src/main/java/com/github/curriculeon/Instructors.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.github.curriculeon;
/*
Use Part 7 as a reference.
Create a Instructors singleton which represents the set of instructors.
Create a TestInstructors class.

*/


import java.util.ArrayList;

public class Instructors extends People<Instructor> {
// ArrayList<Instructor> personList=new ArrayList<Instructor>();
final static Instructors instance = new Instructors();
String [] cohort = new String[]{"Leon","Haseeb"};
private Instructors(){
super();

for(Instructor instructor:peopleMaker(cohort)){
this.add(instructor);
}
}

@Override
public Instructor[] toArray() {
Instructor[] p = new Instructor[this.personList.size()];
for (int i = 0; i < p.length; i++) {
p[i] = this.personList.get(i);
}
return p;

}

public static Instructors getInstance(){
return instance;
}

public ArrayList<Instructor> peopleMaker(String[] names){
ArrayList<Instructor> people=new ArrayList<Instructor>();
for(int i =0;i<names.length;i++){
people.add(studentMaker(Long.valueOf(i+1), names[i]));
}
return people;
}

public Instructor studentMaker(Long id,String name){
Person student =new Student(id,name);

return new Instructor(id,name);
}
/* @Override
public Instructor findByID(Long id) {
for (Instructor instructor : this.personList) {
if (id == instructor.getId()) return (Instructor)instructor;
}
return null;
}*/
}
7 changes: 7 additions & 0 deletions src/main/java/com/github/curriculeon/Learner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.curriculeon;

public interface Learner {

public void learn(Double numOfHours);
public Double getTotalStudyTime();
}
81 changes: 81 additions & 0 deletions src/main/java/com/github/curriculeon/People.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.github.curriculeon;

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

/*
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 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>.
*/
abstract public class People <SomePerson extends Person> implements Iterable<SomePerson> {
ArrayList<SomePerson> personList =new ArrayList();

public People() {

}


public void add(SomePerson person) {
this.personList.add(person);
}

People(ArrayList people){
this.personList=people;
}

public SomePerson findByID(Long id) {
for (SomePerson person : this.personList) {
if (id == person.getId()) return person;
}
return null;
}


public Boolean removePerson(SomePerson person) {
return personList.remove(person);

}

public Boolean removePerson(Long id) {
for (Person p : this.personList) {
if (id.equals(p)) this.personList.remove(p);
return true;
}
return false;

}

public void removeAll() {
for (SomePerson p : this.personList) this.personList.remove(p);
}

public Integer sizeList() {
return this.personList.size();
}

/* public SomePerson[] toArr() {
SomePerson[] p = new SomePerson[this.personList.size() - 1];
for (int i = 0; i < p.length; i++) {
p[i] = this.personList.get(i + 1);
}
return p;
}
*/
@Override
public Iterator<SomePerson> iterator() {
return personList.iterator();
}

abstract public SomePerson[] toArray();
}
20 changes: 20 additions & 0 deletions src/main/java/com/github/curriculeon/Person.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
package com.github.curriculeon;

public class Person {
final Long id;
public long getId() {
return id;
}

public String getName() {
return name;
}

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

String name;

Person(long id, String name){

this.id = id;
this.name=name;
}

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

/*
Create a Student class such that:
Student is a subclass of Person
Student implements the Learner interface
Student should have an instance variable totalStudyTime of type double
Student should have a concrete implementation of the learn method which increments the totalStudyTime variable by the specified numberOfHours argument.
Student should have a getTotalStudyTime() method which returns the totalStudyTime instance variable.
*/

public class Student extends Person implements Learner {
Double totalStudyTime;

Student(long id, String name) {
super(id, name);
this.totalStudyTime=0.0;
}

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

@Override
public Double getTotalStudyTime() {
return this.totalStudyTime;
}
}
64 changes: 64 additions & 0 deletions src/main/java/com/github/curriculeon/Students.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.github.curriculeon;
/*
Part 7.1 - Create Students singleton
Note: The creation of this class will demonstrate an implementation of singleton design pattern.
Create a Students class. (Done)
The class should be an unextendable subclass of the People class. (Done with final)
The class should statically instantiate a final field named INSTANCE of type Students.
The class should define a private nullary constructor which populates the INSTANCE field with respective
Student representations of your colleagues.
Each student should have a relatively unique id field.
The class should define a getInstance method which returns the INSTANCE field.
Part 7.0 - Test Students singleton
Create a TestStudents class.
Create a test method which ensures that each of the students in your current cohort are in your Students singleton.

*/


import java.util.ArrayList;

public class Students extends People<Student> {
// ArrayList<Student> personList=new ArrayList<>();
final static Students instance = new Students();
String [] cohort = new String[]{"David","Chris","Marcus","Leon","Mondira","Deepti","Steve","Yuru","Monica","Akila","Julia","David","Alonzo","Rachid","Emmanuel","Lionel","Solomon","People who don't speak"};
private Students(){
super();

for(Student student:peopleMaker(cohort)){
this.add(student);
}
}
public static Students getInstance(){
return instance;
}

public ArrayList<Student> peopleMaker(String[] names){
ArrayList<Student> stu =new ArrayList<>();
for(int i =0;i<names.length;i++){
stu.add(studentMaker(Long.valueOf(i+1), names[i]));
}
return stu;
}

public Student studentMaker(Long id,String name){
Person student =new Student(id,name);

return new Student(id,name);
}
@Override
public Student[] toArray() {
Student[] p = new Student[this.personList.size()];
for (int i = 0; i < p.length; i++) {
p[i] = this.personList.get(i);
}
return p;
}
@Override
public Student findByID(Long id) {
for (Student student : instance.personList) {
if (id == student.getId()) return student;
}
return null;
}
}
Loading