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
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
<version>1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/com/dtcc/projects/Classroom.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.dtcc.projects;

import java.util.ArrayList;
import java.util.HashMap;


public class Classroom {

private static ArrayList<Student> students = JavaAcademy.getStudents();
private static ArrayList<Instructor> instructors = DelTech.getInstructors();

public static HashMap<String, Person> getRoster(){
//Adds instructors to class
HashMap<String, Person> roster = new HashMap<>();
for(Instructor instructor : instructors){
roster.put(instructor.getName(), instructor);
}

for(Student student : students){
roster.put(student.getName(), student);
}

return roster;
}
}
25 changes: 25 additions & 0 deletions src/main/java/com/dtcc/projects/DelTech.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.dtcc.projects;

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

public class DelTech {

private static ArrayList<Instructor> instructorList = new ArrayList<Instructor>();

static { // static initializer
String[] instructorNames = {"Brian", "Kaleb", "Zan"};
for (String instructorName : instructorNames) {
Instructor instructor = new Instructor(instructorName);
hire(instructor);
}
}

public static ArrayList<Instructor> getInstructors(){return instructorList;}
public static void hire(Instructor teacher){
instructorList.add(teacher);
}
public static void fireStaff(){
instructorList.clear();
}
}
25 changes: 25 additions & 0 deletions src/main/java/com/dtcc/projects/Instructor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.dtcc.projects;

public class Instructor extends Person implements Teacher {

public Instructor(){}

public Instructor(String name){
this.name = name;
}

@Override
public void teach(Student student, double numberOfHours) {
student.learn(numberOfHours);
}

@Override
public void lecture(Student[] student, double numberOfHours) {
double numberOfHoursPerStudent = numberOfHours / student.length;
for(int i = 0; i < student.length; i++){
Student temp_student = student[i];
temp_student.learn(numberOfHoursPerStudent);
student[i] = temp_student;
}
}
}
23 changes: 23 additions & 0 deletions src/main/java/com/dtcc/projects/JavaAcademy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.dtcc.projects;

import java.util.ArrayList;

public class JavaAcademy {

private static ArrayList<Student> studentList = new ArrayList<Student>();

static { // static initializer
String[] studentNames = { "Jessica", "Emad", "Cedric", "Lolu", "Apoorva", "Vara", "Craig", "Robert",
"Stephen", "Ferdinand", "Charu" };
for (String studentName : studentNames) {
Student student = new Student(studentName);
studentList.add(student);
}
}

public static ArrayList<Student> getStudents(){return studentList;}
public static void recruitStudent(Student student){studentList.add(student);}
public static void removeStudents(){studentList.clear();}


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

public interface Learner {

public void learn(double numberOfHours);

}
14 changes: 14 additions & 0 deletions src/main/java/com/dtcc/projects/Person.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
package com.dtcc.projects;

public class Person {

String name;

public Person(){}

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

public String getName(){return this.name;}

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

public class Student extends Person implements Learner {

private double totalStudyTime;

public Student(){}

public Student(String name){this.name = name;}

@Override
public void learn(double numberOfHours) {
//Increment total study time by val
totalStudyTime += numberOfHours;
}

//returns total study time, future calcs
public double getTotalStudyTime(){return this.totalStudyTime;}
}
7 changes: 7 additions & 0 deletions src/main/java/com/dtcc/projects/Teacher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.dtcc.projects;

public interface Teacher {

public void teach(Student student, double numberOfHours);
public void lecture(Student[] student, double numberOfHours);
}
28 changes: 28 additions & 0 deletions src/test/java/com/dtcc/projects/TestClassRoom.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.dtcc.projects;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.HashMap;


public class TestClassRoom {

@Test
public void testRoster(){
//gets roster
HashMap<String, Person> clazz = Classroom.getRoster();

for(Instructor instructor: DelTech.getInstructors()){
//Ensures instructor exists in class
Assert.assertTrue(clazz.containsKey(instructor.getName()));
//Ensure names match
Assert.assertEquals(instructor, clazz.get(instructor.getName()));
}
for(Student student: JavaAcademy.getStudents()){
Assert.assertTrue(clazz.containsKey(student.getName()));
Assert.assertEquals(student, clazz.get(student.getName()));
}

}
}
46 changes: 46 additions & 0 deletions src/test/java/com/dtcc/projects/TestDeltech.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.dtcc.projects;

import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;

public class TestDeltech extends DelTech {

@Before
public void setup(){
//Fires everyone, blank list for every test
fireStaff();
}

@Test
public void testFireStaff(){
ArrayList<Instructor> temp_list = new ArrayList<Instructor>();
temp_list = getInstructors();
Assert.assertEquals(true, temp_list.isEmpty());
}

@Test
public void testHireStaff(){
//All people were fired, hires new overlord Cedric
Instructor cs = new Instructor("Cedric");
Instructor zn = new Instructor("Zan");

//Officially hires him and adds to Instructor roster
hire(cs);
hire(zn);

//Creates temp test arrayList
ArrayList<Instructor> temp_list = new ArrayList<Instructor>();

//Copy
temp_list = getInstructors();

String temp_string1 = temp_list.get(0).getName();
String temp_string2 = temp_list.get(1).getName();

Assert.assertEquals("Cedric", temp_string1);
Assert.assertEquals("Zan", temp_string2);
}
}
100 changes: 100 additions & 0 deletions src/test/java/com/dtcc/projects/TestInstructor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.dtcc.projects;

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

public class TestInstructor {

@Test
public void testImplementation(){
//Create new teach
Instructor zc = new Instructor();
zc.setName("Zan");

//Create New Student
Student cs = new Student();
cs.setName("Cedric");

//Havn't studied yet should be 0
double bookMark1 = cs.getTotalStudyTime();

//Zan teaches student, have to call teacher interface
zc.teach(cs, 2.0);

//Get students study time
double bookMark2 = cs.getTotalStudyTime();

Assert.assertEquals(0.0, bookMark1);
Assert.assertEquals(2.0, bookMark2);

}

@Test
public void testInheritance(){
//Creates an instructor
Instructor kb = new Instructor();
//Set name only exists in Person
kb.setName("Kaleb");
String temp_val = kb.getName();
Assert.assertEquals("Kaleb", temp_val );
}

@Test
public void testTeach(){
//Create new teach
Instructor zc = new Instructor();
zc.setName("Zan");

//Create New Student
Student cs = new Student();
cs.setName("Cedric");

//Havn't studied yet should be 0
double bookMark1 = cs.getTotalStudyTime();

//Zan teaches student, have to call teacher interface
zc.teach(cs, 2);

//Due to last statment we should hope this is true
double bookMark2 = cs.getTotalStudyTime();

Assert.assertEquals(0.0, bookMark1);
Assert.assertEquals(false, (cs.getTotalStudyTime() == 1));
Assert.assertEquals(2.0, bookMark2);
}

@Test
public void testLecture(){

//Create new teach
Instructor zc = new Instructor();
zc.setName("Zan");

//Create New Student
Student cs = new Student();
cs.setName("Cedric");

//Creates second student
Student ez = new Student();
ez.setName("Emad");

//Created a roster of students
Student[] roster = new Student[2];
roster[0] = cs;
roster[1] = ez;

//Teach the whole class 2 hours each
zc.lecture(roster, 4);

//Cedric Gets a special tutor session, so should have 4 total
zc.teach(cs, 2);

//Checking Roster
Assert.assertEquals(2.0, roster[1].getTotalStudyTime());
Assert.assertEquals(4.0, roster[0].getTotalStudyTime());

//Checking each student manually
Assert.assertEquals(2.0, ez.getTotalStudyTime());
Assert.assertEquals(4.0, cs.getTotalStudyTime());
}
}
48 changes: 48 additions & 0 deletions src/test/java/com/dtcc/projects/TestJavaAcademy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.dtcc.projects;

import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;

public class TestJavaAcademy extends JavaAcademy {

@Before
public void setup(){
//Everbody failed! kick them out
removeStudents();
}

@Test
public void testRemoveStudents(){
ArrayList<Student> temp_list = new ArrayList<Student>();
temp_list = getStudents();
Assert.assertEquals(true, temp_list.isEmpty());
}

@Test
public void testRecruitStudents(){
//All people failed, Realized Cedric was star pupil, dropped by mistake
//Add him back to system... Kaleb was a sucky prof and needed lessons /s
Student cs = new Student("Cedric");
Student kb = new Student("Kaleb");

//Officially added back to student roster
recruitStudent(cs);
recruitStudent(kb);

//Creates temp test arrayList
ArrayList<Student> temp_list = new ArrayList<Student>();

//Copy
temp_list = getStudents();

//Get name or else mem location
String temp_string1 = temp_list.get(0).getName();
String temp_string2 = temp_list.get(1).getName();

Assert.assertEquals("Cedric", temp_string1);
Assert.assertEquals("Kaleb", temp_string2);
}
}
Loading