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

public class Instructor extends Person implements Teacher {


public void teach(Learner learner, double numberOfHours) {
learner.learn(numberOfHours);
}


public void lecture(Learner[] learners, double numberOfHours) {
double numberOfHoursPerStudent = numberOfHours/learners.length;
for (int count = 0; count < learners.length; count++){
learners[count].learn(numberOfHoursPerStudent);
}
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/github/curriculeon/Learner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.github.curriculeon;

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

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

public class People<E> implements Iterable<E> {
private List<Person> personList;

public void add(Person person){
personList.add(person);
}
public Person findById(long id){
if(personList.contains(id)){
return null;
}
else{
return null;
}
}
public boolean contains(Person person){
return personList.contains(person);
}
public void remove(Person person){
personList.remove(person);
}
public void remove(long id){
personList.remove(id);
}
public void removeAll(){
personList.clear();
}
public Integer count(){
return personList.size();
}
public Person[] toArray(){
return (Person[]) personList.toArray();
}

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

public class Person {
private final long id;
private String name;

Person(){
id = 0;
name = "";
}
Person(long i, String s){
id = i;
name = s;
}

public long getId() {
return id;
}

public String getName() {
return name;
}

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

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

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

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

public Student(Double numOfHours){
super();
learn(numOfHours);
}
public void learn(Double numberOfHours) {
totalStudyTime += numberOfHours;
}


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

public class Students {
final private static Students INSTANCE;

private Students(){

}

static{
try{
INSTANCE = new Students();
}
catch(Exception e){
throw new RuntimeException("Error in creating singleton instance");
}
}

public static Students getInsatnce() {
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 teach(Learner learner, double numberOfHours);
void lecture(Learner[] learners, double numberOfHours);
}
75 changes: 75 additions & 0 deletions src/test/java/com/github/curriculeon/TestInstructor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.github.curriculeon;
import org.junit.Assert;
import org.junit.Test;

public class TestInstructor {
public void testImplementation(){
//Given
Object instructorOne = new Instructor();

//When

//Then
Assert.assertTrue(instructorOne instanceof Teacher);
}
public void testInheritance(){
//Given
Object instructorTwo = new Instructor();
//When

//Then
Assert.assertTrue(instructorTwo instanceof Person);
}
public void testTeach(Double hoursToAdd){
//Given
Instructor instructorThree = new Instructor();
Student studentOne = new Student();
Double currentStudentHours = studentOne.getTotalStudyTime();
Double expectedStudentHours = currentStudentHours + hoursToAdd;

//When
instructorThree.teach(studentOne, hoursToAdd);
Double actualStudentHours = studentOne.getTotalStudyTime();

//Then
Assert.assertEquals(actualStudentHours, expectedStudentHours);
}
public void testLecture(Double hours){
//Given
Teacher instructorFour = new Instructor();
Learner[] students = new Learner[]{
new Student(0l, "Marcus"),
new Student(1L, "Luke"),
new Student(2L, "Zach")
};
Double expectedHours = hours/students.length;
//When
instructorFour.lecture(students, hours);
//Then
for(int i = 0; i < students.length; i++){
Learner learner = students[i];
Double actualHours = learner.getTotalStudyTime();
Assert.assertEquals(actualHours,expectedHours);
}
}

@Test
public void test0(){
testImplementation();
}

@Test
public void test1(){
testInheritance();
}

@Test
public void test2(){
testTeach(5.0);
}

@Test
public void test3(){
testLecture(5.0);
}
}
37 changes: 36 additions & 1 deletion src/test/java/com/github/curriculeon/TestPerson.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
package com.github.curriculeon;

import org.junit.Assert;
import org.junit.Test;
public class TestPerson {

private void testConstructor(long expectedLong, String expectedString){
Person person = new Person(expectedLong, expectedString);

long actualLong = person.getId();
String actualString = person.getName();

Assert.assertEquals(expectedLong, actualLong);
Assert.assertEquals(expectedString, actualString);
}

public void testSetName(String expectedString){
Person person = new Person();

person.setName(expectedString);
String actualString = person.getName();

Assert.assertEquals(expectedString, actualString);

}

@Test
public void test0(){
testConstructor(1, "Marcus");
}

@Test
public void test1(){
testSetName("Marcus Katalenas");
}

@Test
public void test2(){
testSetName("");
}
}
56 changes: 56 additions & 0 deletions src/test/java/com/github/curriculeon/TestStudent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.github.curriculeon;
import org.junit.Assert;
import org.junit.Test;

public class TestStudent {

public void testImplementation(){
//Given
Student studentOne = new Student();
//When
Boolean result = studentOne instanceof Learner;
//Then

Assert.assertTrue(result);

}
public void testInheritance(){
//Given
Student studentTwo = new Student();

//Where
Boolean result = studentTwo instanceof Person;
//Then

Assert.assertTrue(result);
}
public void testLearn(Double expectedTimeToAdd){
//Given
Student studentThree = new Student(4.5);
//Where
Double actualHours = studentThree.getTotalStudyTime() + expectedTimeToAdd;
//Then
studentThree.learn(expectedTimeToAdd);
Double newHours = studentThree.getTotalStudyTime();
Assert.assertEquals(newHours, actualHours);
}

@Test
public void test0(){
testImplementation();
}

@Test
public void test1(){
testInheritance();
}

@Test
public void test2(){
testLearn(5.5);
}
}