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
22 changes: 22 additions & 0 deletions src/main/java/com/dtcc/projects/ClassRoom.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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();

HashMap<String, Person> hash = new HashMap<>();

HashMap<String, Person> getRoster(){
for(int i = 0; i < students.size(); i++){
hash.put(students.get(i).getStudentName(),new Person(students.get(i).getStudentName()));
}
for(int j = 0; j < instructors.size(); j++){
hash.put(students.get(j).getStudentName(),new Person(students.get(j).getStudentName()));
}
return hash;
}

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

import java.util.ArrayList;

public class DelTech {
private static ArrayList<Instructor> instructorList = new ArrayList<>();

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

public static ArrayList<Instructor> getInstructors() {
return instructorList;
}

public static void fireStaff(){
instructorList.clear();
}

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

public class Instructor extends Person implements Teacher {
private String instructorName;
private double numberOfHoursPerStudent;

public Instructor(){

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

public String getInstructorName() {
return instructorName;
}

public double getNumberOfHoursPerStudent() {
return numberOfHoursPerStudent;
}

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

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

import java.util.ArrayList;

public class JavaAcademy {
private static ArrayList<Student> studentList = new ArrayList<>();

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 void recruitStudent(Student student){
studentList.add(student);
}

public static ArrayList<Student> getStudents() {
return studentList;
}

public static void removeStudents(){
studentList.clear();
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/dtcc/projects/Learner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.dtcc.projects;

public interface Learner {

public void learn(double numberOfHours);
}
15 changes: 15 additions & 0 deletions src/main/java/com/dtcc/projects/Person.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
package com.dtcc.projects;

public class Person {
private String name;

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

public String getName(){
return name;
}

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

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

public class Student extends Person implements Learner{
private double totalStudyTime;
private String studentName;

public Student(){

}

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

public void learn(double numberOfHours) {
this.totalStudyTime = this.totalStudyTime + numberOfHours;
}

public double getTotalStudyTime() {
return totalStudyTime;
}

public String getStudentName() {
return studentName;
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/dtcc/projects/Teacher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.dtcc.projects;

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

import junit.framework.TestCase;
import org.junit.Assert;

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

public class ClassRoomTest extends TestCase {
ClassRoom classRoom;
HashMap<String, Person> map = new HashMap<>();
public void setUp() {
classRoom = new ClassRoom();
map = classRoom.getRoster();
}

public void testGetRosterKeys() {
Assert.assertEquals(11,map.size());
Assert.assertTrue(map.containsKey("Lolu"));
}

public void testGetRosterValues(){
for(Map.Entry<String, Person> enter : map.entrySet()){
String key = enter.getKey();
Person pers = enter.getValue();
Assert.assertEquals(key,pers.getName());
}
}
}
26 changes: 26 additions & 0 deletions src/test/java/com/dtcc/projects/DelTechTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.dtcc.projects;

import junit.framework.TestCase;
import org.junit.Assert;

import java.util.ArrayList;

public class DelTechTest extends TestCase {
DelTech delTech;
ArrayList<Instructor> instruct;
public void setUp() throws Exception {
delTech = new DelTech();
DelTech.fireStaff();
}

public void testHire() {
String actual = "Vara";
DelTech.hire(new Instructor(actual));
instruct = DelTech.getInstructors();
Assert.assertEquals("Vara",instruct.get(0).getInstructorName());
}

public void testFireStaff() {
Assert.assertEquals(0,DelTech.getInstructors().size());
}
}
35 changes: 35 additions & 0 deletions src/test/java/com/dtcc/projects/InstructorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.dtcc.projects;

import junit.framework.TestCase;
import org.junit.Assert;

public class InstructorTest extends TestCase {

private Instructor instructor;

public void setUp() {
instructor = new Instructor();
}

public void testImplementation() {
Assert.assertTrue(instructor instanceof Teacher);
}

public void testInheritance() {
Assert.assertTrue(instructor instanceof Person);
}

public void testTeach() {
Student student = new Student("Lolu");
instructor.teach(student, 8);
double expected = student.getTotalStudyTime();
Assert.assertEquals(8,expected,1);
}

public void testLecture() {
Student[] students = {new Student("Lolu")};
instructor.lecture(students, 8);
double expected = instructor.getNumberOfHoursPerStudent();
Assert.assertEquals(8,expected,1);
}
}
25 changes: 25 additions & 0 deletions src/test/java/com/dtcc/projects/JavaAcademyTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.dtcc.projects;

import junit.framework.TestCase;
import org.junit.Assert;

import java.util.ArrayList;

public class JavaAcademyTest extends TestCase {
JavaAcademy javaAcademy;

public void setUp() throws Exception {
javaAcademy = new JavaAcademy();
JavaAcademy.removeStudents();
}
public void testRecruitStudent() {
Student student = new Student("Zoe");
String actual = "Zoe";
JavaAcademy.recruitStudent(student);
Assert.assertEquals("Zoe",JavaAcademy.getStudents().get(0).getStudentName());
}

public void testRemoveStudents() {
Assert.assertTrue(JavaAcademy.getStudents().isEmpty());
}
}
19 changes: 19 additions & 0 deletions src/test/java/com/dtcc/projects/TestPerson.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
package com.dtcc.projects;

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

public class TestPerson {

@Test
public void testSetName(){
String expected = "Lolu";
Person person = new Person(expected);
String actual = person.getName();
Assert.assertEquals(expected, actual);
}

@Test
public void testConstructor(){
String expected = "Lolu";
Person person = new Person(expected);
String actual = person.getName();
Assert.assertEquals(expected, actual);
}
}
26 changes: 26 additions & 0 deletions src/test/java/com/dtcc/projects/TestStudent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.dtcc.projects;

import junit.framework.TestCase;
import org.junit.Assert;

public class TestStudent extends TestCase {
Student student;
public void setUp() throws Exception {
student = new Student();
}

public void testImplementation() {
Assert.assertTrue(student instanceof Learner);
}

public void testLearn() {
student.learn(5.00);
double actual = 5.00;
double expected = student.getTotalStudyTime();
Assert.assertEquals(actual,expected,1);
}

public void testInheritance() {
Assert.assertTrue(student instanceof Person);
}
}
Binary file added target/classes/com/dtcc/projects/ClassRoom.class
Binary file not shown.
Binary file added target/classes/com/dtcc/projects/DelTech.class
Binary file not shown.
Binary file added target/classes/com/dtcc/projects/Instructor.class
Binary file not shown.
Binary file not shown.
Binary file added target/classes/com/dtcc/projects/Learner.class
Binary file not shown.
Binary file added target/classes/com/dtcc/projects/Person.class
Binary file not shown.
Binary file added target/classes/com/dtcc/projects/Student.class
Binary file not shown.
Binary file added target/classes/com/dtcc/projects/Teacher.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.