Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
62db0e9
created person class
mnaser11218 Oct 27, 2024
bdf0c66
completed learner interface, student and peson class
mnaser11218 Oct 27, 2024
733663a
Merge pull request #1 from mnaser11218/mohammed
mnaser11218 Oct 27, 2024
dbaa01b
completed instructor class and teacher interface
mnaser11218 Oct 27, 2024
622c8c9
Merge pull request #2 from mnaser11218/mohammed
mnaser11218 Oct 27, 2024
f593c20
completed until the people clasS
mnaser11218 Oct 27, 2024
abe4cbf
completed classes, need to complete methods in classroom enum
mnaser11218 Oct 27, 2024
c6fc405
Merge pull request #3 from mnaser11218/mohammed
mnaser11218 Oct 27, 2024
b8e3feb
added test for person class
mnaser11218 Nov 11, 2024
3940b69
Merge pull request #4 from mnaser11218/mohammed
mnaser11218 Nov 11, 2024
36b082e
added test for student class
mnaser11218 Nov 11, 2024
5623cbb
Merge pull request #5 from mnaser11218/mohammed
mnaser11218 Nov 11, 2024
d2f5601
updated teacher interface
mnaser11218 Nov 11, 2024
e44c1bd
updated Instructor class
mnaser11218 Nov 11, 2024
19f7172
Merge pull request #6 from mnaser11218/mohammed
mnaser11218 Nov 11, 2024
9a85ede
completed test for testInstructor class
mnaser11218 Nov 11, 2024
adca35b
Merge pull request #7 from mnaser11218/mohammed
mnaser11218 Nov 11, 2024
c099870
updated people class
mnaser11218 Nov 11, 2024
77c6147
Merge pull request #8 from mnaser11218/mohammed
mnaser11218 Nov 11, 2024
6f67e26
added employee class to practice static variables and singletons
mnaser11218 Nov 11, 2024
d7995eb
Merge pull request #9 from mnaser11218/mohammed
mnaser11218 Nov 11, 2024
3e71855
added students class instance field
mnaser11218 Nov 11, 2024
a743636
Merge pull request #10 from mnaser11218/mohammed
mnaser11218 Nov 11, 2024
533da6f
completed TestStudents class
mnaser11218 Nov 11, 2024
f9a6066
Merge pull request #11 from mnaser11218/mohammed
mnaser11218 Nov 11, 2024
dbdfd9f
completed instructors class and created test for Instructors
mnaser11218 Nov 11, 2024
9ed9973
Merge pull request #12 from mnaser11218/mohammed
mnaser11218 Nov 11, 2024
b195052
completed classroom enum class
mnaser11218 Nov 11, 2024
c5e9442
Merge pull request #13 from mnaser11218/mohammed
mnaser11218 Nov 11, 2024
25b7732
completed classroom tests
mnaser11218 Nov 12, 2024
af11a58
Merge pull request #14 from mnaser11218/mohammed
mnaser11218 Nov 12, 2024
880bc1d
updated people class made it generic and abstract
mnaser11218 Nov 12, 2024
b6970d7
modified people class
mnaser11218 Nov 12, 2024
36e6708
updated testinstructor class
mnaser11218 Nov 12, 2024
ce5ec7a
completed educator enum and educator test class
mnaser11218 Nov 12, 2024
24ea0a4
tested hostlecture can take educator as instructor
mnaser11218 Nov 12, 2024
f2980e6
Merge pull request #15 from mnaser11218/mohammed
mnaser11218 Nov 12, 2024
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
Binary file added .DS_Store
Binary file not shown.
29 changes: 29 additions & 0 deletions src/main/java/com/github/curriculeon/Classroom.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.github.curriculeon;

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

public enum Classroom {
INSTANCE;
private Students students = Students.getInstance();
private Instructors instructors = Instructors.getInstance();


public void hostLecture(Teacher teacher, Double numberOfHours){
Student[] personArray = students.toArray();
teacher.lecture(personArray, numberOfHours);
}
public void hostLecture(Long id, Double numberOfHours){
Teacher teacher = Instructors.getInstance().findById(id);
hostLecture(teacher, numberOfHours);
}
public Map<Student, Double> getStudyMap(){
Map<Student, Double> map = new HashMap<>();
for(Student student : Students.getInstance().toArray()){
double numberOfHours = student.getTotalStudyTime();
map.put(student, numberOfHours);
}
return map;
}

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

public enum Educator implements Teacher{
MOHAMMED, AYAD, NASER;
private final Instructor instructor;
private Double hoursWorked = 0.0;


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

}

@Override
public void lecture(Learner[] learners, Double time) {
this.instructor.lecture(learners, time);
this.hoursWorked += time;
}

@Override
public void teach(Learner learner, Double time) {
this.instructor.teach(learner, time);
this.hoursWorked+= time;
}
}
42 changes: 42 additions & 0 deletions src/main/java/com/github/curriculeon/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.github.curriculeon;

public class Employee {
public static Employee LEON = new Employee(5l, "leon", 555.0);
public static Employee MOHAMMED = new Employee(1l, "mohammed", 4444.0);
private Long id;
private String name;
private Double salary;

private Employee() {
}

private Employee(Long id, String name, Double salary) {
this.id = id;
this.name = name;
this.salary = salary;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return name;
}

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

public Double getSalary() {
return salary;
}

public void setSalary(Double salary) {
this.salary = salary;
}
}
21 changes: 21 additions & 0 deletions src/main/java/com/github/curriculeon/Instructor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.github.curriculeon;

public class Instructor extends Person implements Teacher{
public Instructor() {
}

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

public void teach(Learner learner, Double time){
learner.learn(time);
}
public void lecture (Learner[] learners, Double time){
double numberOfHoursPerLearner = time / learners.length;
for(Learner learner : learners){
teach(learner, numberOfHoursPerLearner);
}
}

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

public final class Instructors extends People<Instructor>{
private static Instructors INSTANCE = new Instructors();
private Instructors() {
this.add(new Instructor(1l, "mohammed"));
this.add(new Instructor(2l, "ayad"));
this.add(new Instructor(3l, "naser"));

}

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

public static Instructors getInstance(){
return INSTANCE;
}

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

public interface Learner {
void learn(Double hours);
Double getTotalStudyTime();


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

public class Main {
public static void main(String[] args) {
Employee employee = Employee.LEON;
Employee employee2 = Employee.MOHAMMED;
System.out.println(employee.getId() + employee.getName());
System.out.println(employee2.getName());

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

import java.util.*;

abstract class People <PersonType extends Person> implements Iterable<PersonType>{
//protected indicates that only subclasses have access to this field
protected List<PersonType> personList = new ArrayList<>();
public People() {
}
public void add(PersonType person){
personList.add(person);
}
public PersonType findById(Long id){
for(PersonType person : personList){
if(person.getId() == id){
return person;
}
}
return null;
}

public boolean contains(PersonType person){
boolean results = false;
for(PersonType ele: personList){
if(ele.equals(person)){
results = true;
break;
}
}

return results;
}
public void remove(PersonType person){
personList.remove(person);
}

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

public void removeAll(){
this.personList.clear();
}
public Integer count(){
return this.personList.size();
}
abstract public PersonType[] toArray();


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

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

public Person() {
}

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

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/github/curriculeon/Student.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.github.curriculeon;

public class Student extends Person implements Learner{
private Double totalStudyTime=0.0;

public Student(Double totalStudyTime) {
this.totalStudyTime = totalStudyTime;
}

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

public Student() {

}

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

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

public final class Students extends People<Student>{
private static Students INSTANCE = new Students();
private Students() {
this.add(new Student(5l, "mohammed"));
this.add(new Student(9l, "naser"));
this.add(new Student(4l, "ayad"));

}

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

public static Students getInstance(){
return INSTANCE;
}
}
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 lecture (Learner [] learners, Double numberOfHours);
void teach(Learner learner, Double numberOfHours);
}
34 changes: 34 additions & 0 deletions src/test/java/com/github/curriculeon/TestClassroom.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.github.curriculeon;

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

import java.util.Map;

public class TestClassroom {
@Test
public void testHostLecture(){
// given
Classroom classroom = Classroom.INSTANCE;
//Teacher teacher = (Teacher) Instructors.getInstance().findById(1l);
Educator teacher = Educator.AYAD;
double numberOfHours = Students.getInstance().count();
double hoursPerStudent = Students.getInstance().count() / numberOfHours;
Map<Student, Double>preStudyMap = classroom.getStudyMap();

//when
classroom.hostLecture(teacher, numberOfHours);
Map<Student, Double> postStudyMap = classroom.getStudyMap();

for(Map.Entry<Student, Double> entry : preStudyMap.entrySet()){
Student student = entry.getKey();
double preStudyTime = entry.getValue();
double actualStudyTime = postStudyMap.get(student);
double expectedStudyTime = preStudyTime + hoursPerStudent;
//then
Assert.assertEquals(expectedStudyTime, actualStudyTime, 0.0001);
}

}

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

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

public class TestEducator {

@Test
public void testImplementation(){
//given
Educator instructor = Educator.AYAD;

//when
boolean isInstance = instructor instanceof Teacher;


//then
Assert.assertTrue(isInstance);

}


@Test
public void testTeach(){
//given
Educator instructor = Educator.AYAD;
Learner student = new Student();
//when
Double initialTime = student.getTotalStudyTime();
Double studyTime = 5.0;
instructor.teach(student, studyTime);
Double addedTime = initialTime + studyTime;

//then
Assert.assertEquals(student.getTotalStudyTime(), addedTime);
}

@Test
public void testLecture(){
//given
Educator instructor = Educator.AYAD;
Student[] students = new Student[]{new Student(), new Student()};
Student firstStudent = students[0];
//when
Double lectureTime = 50.0;
Double lectureTimeForStudent = lectureTime / students.length;
Assert.assertNotEquals(firstStudent.getTotalStudyTime(), lectureTimeForStudent);
instructor.lecture(students, lectureTime);


//then
Assert.assertEquals(firstStudent.getTotalStudyTime(), lectureTimeForStudent);

}
}
Loading