Commit e41e1d73 authored by 9531304's avatar 9531304

adding second part

parent c47796bc
......@@ -44,7 +44,8 @@ public class Course {
}
public void enrollStudent(Student student){
stds.add(student);
if(student.getDepartment() == this.dpart){
stds.add(student);}
}
......
package com.university;
import java.util.ArrayList;
public class Department {
private String name;
private ArrayList<Student> stds = new ArrayList<Student>();
private Student[] students;
private ArrayList<Course> crs = new ArrayList<Course>();
private Course[] courses;
private ArrayList<Professor> prfs = new ArrayList<Professor>();
private Professor[] professors;
public Department(String name) {
this.name = name;
}
......@@ -11,38 +19,61 @@ public class Department {
}
public void addStudent(Student student){
if(student.getDepartment().getName() == this.name){
stds.add(student);
}
}
public Student[] getStudents(){
return null;
students = stds.toArray(new Student[stds.size()]);
return students;
}
public void removeStudent(Student student){
if(student.getDepartment().getName() == this.name){
for(Student std : students){
if(std == student)
stds.remove(student);}
}
}
public void addCourse(Course course){
if(course.getDepartment().getName() == this.name) {
crs.add(course);
}
}
public Course[] getCourses(){
return null;
courses = crs.toArray(new Course[crs.size()]);
return courses;
}
public void removeCourse(Course course){
crs.remove(course);
}
public void addProfessor(Professor student){
public void addProfessor(Professor professor){
if(professor.getDepartment().getName() == this.name){
prfs.add(professor);
}
}
public Professor[] getProfessors(){
return null;
professors = prfs.toArray(new Professor[prfs.size()]);
return professors;
}
public void removeProfessor(Professor professor){
for(Professor pfs : prfs){
if(pfs == professor){
prfs.remove(professor);
}
}
}
......
package test;
import com.university.Student;
import com.university.Course;
import com.university.Professor;
import com.university.Department;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
import static org.junit.Assert.assertNotEquals;
public class CourseTest {
static Course course;
@BeforeAll
public static void createCourse(){
Department department = new Department("Computer");
Department department1 = new Department("Civil");
Professor professor = new Professor(department , "HajMohammadi");
course = new Course("2122" , "EnteghaleHararat" , department , professor , 21);
Student std1 = new Student("Mohammad" , "9525080" , "Omran" , department1);
course.enrollStudent(std1);
Student std2 = new Student("Karim" , "9321098" , "Electricity" , department);
course.enrollStudent(std2);
Student std3 = new Student("ali" , "9321088" , "Electricity" , department);
course.enrollStudent(std3);
Student std4 = new Student("reza" , "9321078" , "Electricity" , department);
course.enrollStudent(std4);
Student std5 = new Student("farzin" , "9321098" , "Electricity" , department);
course.enrollStudent(std5);
Student std6 = new Student("hossein" , "9321098" , "Electricity" , department);
course.enrollStudent(std6);
Student std7 = new Student("nima" , "9321098" , "Electricity" , department);
course.enrollStudent(std7);
Student std8= new Student("erfan" , "9321098" , "Electricity" , department);
course.enrollStudent(std8);
Student std9 = new Student("javad" , "9321098" , "Electricity" , department);
course.enrollStudent(std9);
Student std10 = new Student("arman" , "9321098" , "Electricity" , department);
course.enrollStudent(std10);
Student[] stds = new Student[]{std1 , std2 , std3 ,std4 , std5 , std6 , std7 , std8 , std9 , std10};
}
@Test
public void testCourseGetID(){
assertNotNull(course.getID());
}
@Test
public void testCourseGetDepartment(){
assertNotNull(course.getDepartment());
}
@Test
public void testCourseGetName(){
assertNotNull(course.getName());
}
@Test
public void testCourseGetProfessor(){
assertNotNull(course.getProfessor());
}
@Test
public void testCourseGetEnrollStudents(){
assertNotEquals(1 , course.getStudents().length);
}
@Test
public void testCourseEnrollStudents(){
for(Student std : stds){
}
}
}
package test;
import com.university.Student;
import com.university.Professor;
import com.university.Department;
import com.university.Course;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
import static org.junit.Assert.assertNotEquals;
public class DepartmentTest {
static Department department;
@BeforeAll
public static void CreateDepartment(){
department = new Department("Computer");
Student student = new Student("Ali" , "3212" , "Computer" , department);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment