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

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

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

private HashMap<String,Person> hashmap=new HashMap<>();

public HashMap<String, Person> getRoster(){
for(int i=0;i<students.size();i++){
this.hashmap.put(students.get(i).getStudentName(),new Person(students.get(i).getStudentName()));
}

for(int j=0;j<instructors.size();j++){
this.hashmap.put(instructors.get(j).getInstructorName(),new Person(instructors.get(j).getInstructorName()));
}
return this.hashmap;
}

public HashMap<String, Person> getHashmap() {
return hashmap;
}
//hs.forEach((k, v) -> {System.out.println("Key: " + k + ", Value: " + v);});
}
29 changes: 29 additions & 0 deletions src/main/java/com/dtcc/projects/DelTech.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.dtcc.projects;

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

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 getInstructors(){
return instructorList;
}

public static void fireStaff(){
instructorList.clear();
}
}
31 changes: 31 additions & 0 deletions src/main/java/com/dtcc/projects/Instructor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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;
}
@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;
}

public String getInstructorName() {
return instructorName;
}

public double getNumberOfHoursPerStudent() {
return this.numberOfHoursPerStudent;
}
}
30 changes: 30 additions & 0 deletions src/main/java/com/dtcc/projects/JavaAcademy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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 ArrayList<Student> getStudents() {
return studentList;
}

public static void recruitStudent(Student student){
studentList.add(student);
}

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);
}

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

public class Person {
private 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;
}

}
24 changes: 24 additions & 0 deletions src/main/java/com/dtcc/projects/Student.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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) {
//body of learn method.
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);
}
36 changes: 36 additions & 0 deletions src/test/java/com/dtcc/projects/TestClassRoom.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.dtcc.projects;

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

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

public class TestClassRoom {
ClassRoom classroom;
HashMap<String,Person> hs=new HashMap<>();;
@Before
public void setup(){
classroom=new ClassRoom();
hs=classroom.getRoster();
}

@Test
public void testGetRosterValues(){

for(Map.Entry<String,Person> entry:hs.entrySet()){
String key = entry.getKey();
Person p=entry.getValue();
Assert.assertEquals(key,p.getName());
}
}

@Test
public void testGetRosterKeys(){
Assert.assertEquals(14,hs.size());
Assert.assertTrue(hs.containsKey("Charu"));
Assert.assertTrue(hs.containsKey("Zan"));
Assert.assertFalse(hs.containsKey("Roy"));
}
}
30 changes: 30 additions & 0 deletions src/test/java/com/dtcc/projects/TestDelTech.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.dtcc.projects;

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

import java.util.ArrayList;

public class TestDelTech {
DelTech deltech;
ArrayList<Instructor> list;
@Before
public void setup(){
deltech=new DelTech();
deltech.fireStaff();
}

@Test
public void testFireStaff(){
Assert.assertEquals(0,DelTech.getInstructors().size());
}

@Test //Check later
public void testHireStaff(){
String actual="Jennifer";
deltech.hire(new Instructor(actual));
list=DelTech.getInstructors();
Assert.assertEquals("Jennifer",list.get(0).getInstructorName());
}
}
37 changes: 37 additions & 0 deletions src/test/java/com/dtcc/projects/TestInstructor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.dtcc.projects;

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

public class TestInstructor {

Instructor instructor;
@Before
public void setUp(){
instructor=new Instructor();
}
@Test
public void testImplementation(){
Assert.assertTrue(instructor instanceof Teacher);
}

@Test
public void testInheritance(){
Assert.assertTrue(instructor instanceof Person);
}
@Test
public void testTeach(){
Student student=new Student("Lorrie");
instructor.teach(student,5);
Assert.assertEquals(5,student.getTotalStudyTime(),0);
}

@Test
public void testLecture(){
Student[] students={new Student("Albert"),new Student("Ross"), new Student("Tom")};
instructor.lecture(students,9.00);
Assert.assertEquals(3.00,instructor.getNumberOfHoursPerStudent(),0);

}
}
28 changes: 28 additions & 0 deletions src/test/java/com/dtcc/projects/TestJavaAcademy.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;

public class TestJavaAcademy {
JavaAcademy javaAcademy;

@Before
public void setup(){
javaAcademy=new JavaAcademy();
javaAcademy.removeStudents();
}

@Test
public void testRemoveStudents(){
Assert.assertTrue(JavaAcademy.getStudents().isEmpty());
}

@Test
public void testRecruitStudent(){
Student student= new Student("Nisha");
JavaAcademy.recruitStudent(student);
Assert.assertEquals("Nisha",JavaAcademy.getStudents().get(0).getStudentName());
}
}

25 changes: 25 additions & 0 deletions src/test/java/com/dtcc/projects/TestPerson.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
package com.dtcc.projects;

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

public class TestPerson {
Person person;
//Create a testSetName method which ensures that a Person object's
// name variable is being set by invoking the .setName method.
@Test
public void testSetName(){
person=new Person();
String actual="Charu";
person.setName(actual);
String expected=person.getName();
Assert.assertEquals(actual,expected);
}

//Create a testConstructor method which ensures that a Person object's
// ame variable is being set by invoking the Person constructor.
@Test
public void testConstructor(){
person=new Person("Ellie");
String actual="Ellie";
String expected=person.getName();
Assert.assertEquals(actual,expected);
}
}

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

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

public class TestStudent {
Student student;
@Before
public void setUp(){
student=new Student();
}
@Test
public void testImplementation(){
Assert.assertTrue(student instanceof Learner);
}

@Test
public void testInheritance(){
Assert.assertTrue(student instanceof Person);
}

@Test
public void testLearn(){
student.learn(2.00);
double actual=2.0;
double expected=student.getTotalStudyTime();
Assert.assertEquals(actual,expected,0);
}
}