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

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

public class ClassRoom {

private ArrayList<Student> students = new ArrayList<Student>(); //JavaAcademy.getStudents();
private ArrayList<Instructor> instructors = new ArrayList<Instructor>(); // DelTech.getInstructors();
private HashMap<String, Person> rosters= new HashMap<String, Person>();


public HashMap getRoster(){
for(Person p : students){
rosters.put(p.getName(), p);
}
for(Person p : instructors){
rosters.put(p.getName(), p);
}

return rosters;
}

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

public void setStudents(ArrayList<Student> students) {
this.students = students;
}

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

public void setInstructors(ArrayList<Instructor> instructors) {
this.instructors = instructors;
}
}
28 changes: 28 additions & 0 deletions src/main/java/com/dtcc/projects/DelTech.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.dtcc.projects;

import java.util.ArrayList;

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 void hire(Instructor instructor){
instructorList.add(instructor);
}

public static ArrayList getInstructors(){
return instructorList;
}

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

public class Instructor extends Person implements Teacher {

public Instructor(String name){

}

public void teach(Student student, double noOfHours) {
student.learn(noOfHours);
}

public void lecture(Student[] student, double numberOfHours) {
Student[] students = new Student[10];
double numberOfHoursPerStudent = numberOfHours / students.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<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 void recruitStudent(Student student){
studentList.add(student);

}
public static ArrayList getStudents(){
return studentList;
}
public static void removeStudents(ArrayList students){
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);
}
16 changes: 16 additions & 0 deletions src/main/java/com/dtcc/projects/Person.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
package com.dtcc.projects;

public class Person {
private String name;

public Person(){}

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


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

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

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

public Student(String studentName) {
}

public Student() {

}

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

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

public interface Teacher {

public void teach(Student student, double noOfHours);

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

import org.junit.Test;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;

public class TestClassRoom {


ClassRoom cr = new ClassRoom();
@Test
public void hashMappingTest(){
Set<Person> s = new HashSet<Person>(cr.getRoster().values());
Iterator<Person> it = s.iterator();
while(it.hasNext()){
Person p = it.next();
if(it.next() instanceof Student){
if(!cr.getStudents().contains(p)){
fail();
}
}
if(it.next() instanceof Instructor){

if(!cr.getInstructors().contains(p)){
fail();

}

}

}


}


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

public class TestDelTech {
}
34 changes: 34 additions & 0 deletions src/test/java/com/dtcc/projects/TestInstructor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.dtcc.projects;

import org.hamcrest.core.IsInstanceOf;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

public class TestInstructor {

Instructor instructor = new Instructor("Brian");
@Test
public void testImplementation(){
assertThat(instructor, new IsInstanceOf(Teacher.class));

}
@Test
public void testInheritance(){
assertThat(instructor, new IsInstanceOf(Person.class));
}
@Test
public void testTeach(){
Student s1 = new Student();
instructor.teach(s1, 20);
assertEquals(20, s1.getTotalStudyTime(),0.001);
}
@Test
public void testLecture(){
Student s2 = new Student();
instructor.teach(s2, 20);
assertEquals(20, s2.getTotalStudyTime(),0.001);

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

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

import java.util.ArrayList;

import static org.junit.Assert.*;

public class TestJavaAcademy {
@Before
@Test
public void setup(){
// ArrayList<String> removeStudentList = new ArrayList<String>();
// removeStudentList.add("Tom");
JavaAcademy.removeStudents(JavaAcademy.getStudents());

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

}

@Test
public void testRecruitStudent(){
Student Tom = new Student("Tom");
JavaAcademy.recruitStudent(Tom);
assertTrue(JavaAcademy.getStudents().contains(Tom));

}


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

import static org.junit.Assert.assertEquals;

public class TestPerson {



@Test
public void testsetname(){
Person person = new Person();
String expected = "Mongo";
person.setName("Mongo");

Assert.assertEquals(expected, person.getName());


}
@Test
public void testConstructor(){
String expected = "Mongo";
Person person1 = new Person("Mongo");
Assert.assertEquals(expected, person1.getName());
}

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

import org.hamcrest.core.IsInstanceOf;
import org.junit.Test;
import org.hamcrest.BaseMatcher;

import static org.junit.Assert.*;

public class TestStudent {
Student student = new Student();

@Test
public void testImplementation(){
assertThat(student, new IsInstanceOf(Learner.class));

}
@Test
public void testInheritance(){
assertThat(student, new IsInstanceOf(Person.class));
}
@Test
public void testLearn(){
student.learn(5);
assertEquals(5, student.getTotalStudyTime(), 0.001);
}


}
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.