Commit ff41411e authored by 9531304's avatar 9531304

Complete

parent e41e1d73
...@@ -44,7 +44,7 @@ public class Course { ...@@ -44,7 +44,7 @@ public class Course {
} }
public void enrollStudent(Student student){ public void enrollStudent(Student student){
if(student.getDepartment() == this.dpart){ if(student.getDepartment() == this.dpart && stds.indexOf(student) >= 0){
stds.add(student);} stds.add(student);}
} }
......
...@@ -6,7 +6,7 @@ public class Department { ...@@ -6,7 +6,7 @@ public class Department {
private String name; private String name;
private ArrayList<Student> stds = new ArrayList<Student>(); private ArrayList<Student> stds = new ArrayList<Student>();
private Student[] students; private Student[] students;
private ArrayList<Course> crs = new ArrayList<Course>(); public ArrayList<Course> crs = new ArrayList<Course>();
private Course[] courses; private Course[] courses;
private ArrayList<Professor> prfs = new ArrayList<Professor>(); private ArrayList<Professor> prfs = new ArrayList<Professor>();
private Professor[] professors; private Professor[] professors;
...@@ -19,8 +19,9 @@ public class Department { ...@@ -19,8 +19,9 @@ public class Department {
} }
public void addStudent(Student student){ public void addStudent(Student student){
if(student.getDepartment().getName() == this.name){ if(student.getDepartment().getName() == this.name && stds.indexOf(student) <= -1 ){
stds.add(student); stds.add(student);
} }
} }
...@@ -32,15 +33,13 @@ public class Department { ...@@ -32,15 +33,13 @@ public class Department {
public void removeStudent(Student student){ public void removeStudent(Student student){
if(student.getDepartment().getName() == this.name){ if(student.getDepartment().getName() == this.name){
for(Student std : students){ stds.remove(student);
if(std == student)
stds.remove(student);}
} }
} }
public void addCourse(Course course){ public void addCourse(Course course){
if(course.getDepartment().getName() == this.name) { if(course.getDepartment().getName() == this.name && crs.indexOf(course) <= -1) {
crs.add(course); crs.add(course);
} }
...@@ -57,7 +56,7 @@ public class Department { ...@@ -57,7 +56,7 @@ public class Department {
} }
public void addProfessor(Professor professor){ public void addProfessor(Professor professor){
if(professor.getDepartment().getName() == this.name){ if(professor.getDepartment().getName() == this.name && prfs.indexOf(professor) <= -1){
prfs.add(professor); prfs.add(professor);
} }
......
...@@ -5,7 +5,8 @@ import java.util.ArrayList; ...@@ -5,7 +5,8 @@ import java.util.ArrayList;
public class Professor { public class Professor {
private String name; private String name;
private Department dpart; private Department dpart;
private ArrayList<Course> crs = new ArrayList<Course>(); private ArrayList<Course> cors = new ArrayList<Course>();
private Course[] courses;
public Professor(Department department, String name) { public Professor(Department department, String name) {
this.name = name; this.name = name;
...@@ -21,6 +22,13 @@ public class Professor { ...@@ -21,6 +22,13 @@ public class Professor {
} }
public Course[] getCourses() { public Course[] getCourses() {
return null; for(Course cr : dpart.crs){
if(cr.getProfessor().getName() == this.name){
cors.add(cr);
}
}
courses = cors.toArray(new Course[cors.size()]);
return courses;
} }
} }
package com.university;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class StudnetTest {
static Student student;
static Department department;
@BeforeAll
public static void createStudent(){
department = new Department("Computer and IT Eng");
student = new Student("Alireza", "1234", "Software Eng", department);
}
@Test
public void testStudentGetName(){
assertEquals("Alireza", student.getName());
}
@Test
public void testStudenGetCourses(){
assertNotNull(student.getCourses());
assertEquals(0, student.getCourses().length);
}
}
package com.university; package com.university;
import java.util.ArrayList;
public class University { public class University {
private String name;
private ArrayList<Department> dprmts = new ArrayList<Department>();
private Department[] departments;
public University(String name){
this.name = name;
}
public String getName(){
return name;
}
public Department[] getDepartments(){ public Department[] getDepartments(){
return null; departments = dprmts.toArray(new Department[dprmts.size()]);
return departments;
} }
public void addDepartment(Department department){ } public void addDepartment(Department department){
if(dprmts.indexOf(department)<= -1)
dprmts.add(department);
}
public void removeDepartment(Department department){ } public void removeDepartment(Department department){
if(dprmts.indexOf(department) >= 0){
dprmts.remove(department);
}
}
} }
package com.university;
public class test {
public static void main(String[] args){
Department dp = new Department("amirkabir");
Student st = new Student("Mohammad" , "1234" , "Mechanic" , dp);
System.out.println(st.getName());
}
}
...@@ -66,8 +66,6 @@ public class CourseTest { ...@@ -66,8 +66,6 @@ public class CourseTest {
} }
@Test @Test
public void testCourseEnrollStudents(){ public void testCourseEnrollStudents(){
for(Student std : stds){
}
} }
} }
...@@ -12,12 +12,62 @@ import static junit.framework.TestCase.assertNotNull; ...@@ -12,12 +12,62 @@ import static junit.framework.TestCase.assertNotNull;
import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotEquals;
public class DepartmentTest { public class DepartmentTest {
static Department department; static Department department , department2;
@BeforeAll @BeforeAll
public static void CreateDepartment(){ public static void CreateDepartment(){
department = new Department("Computer"); department = new Department("Computer");
Student student = new Student("Ali" , "3212" , "Computer" , department); Student student = new Student("Ali" , "3212" , "Computer" , department);
Professor professor1 = new Professor(department , "salmani");
department.addStudent(student);
department2 = new Department("mechanic");
Professor professor2 = new Professor(department2 , "Ohadi");
Student student1 = new Student("Mohammad" , "9321078" , "Mechanic" , department2);
department2.addStudent(student);
Student student2 = new Student("Ali" , "1234" , "Computer" , department);
department.addStudent(student2);
department.removeStudent(student);
Student student3 = new Student("reza" , "2132" , "Computer" , department);
department.addStudent(student3);
Course course1 = new Course("12" , "ap" , department , professor1 , 21 );
department.addCourse(course1);
Course course2 = new Course("12" , "ap" , department2 , professor2 , 21 );
department.removeCourse(course2);
department.addProfessor(professor1);
department2.addProfessor(professor1);
}
@Test
public void TestAddStudent(){
assertEquals(0 , department2.getStudents().length); //can't add student
assertNotNull(department.getStudents().length);
}
@Test
public void TestremoveStudents(){
assertEquals(2 , department.getStudents().length);
}
@Test
public void TestGetName0(){
assertEquals("Computer" , department.getName());
}
@Test
public void TestAddCourse(){
assertNotNull(department.getCourses().length);
assertEquals(0 , department2.getCourses().length);
} }
@Test
public void TestAddProfessor(){
assertNotNull(department.getProfessors().length);
assertEquals(0 , department2.getProfessors().length);
}
} }
package test;
import com.university.*;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertEquals;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
public class TestProfessor {
static Professor professor;
@BeforeAll
public static void CreateProfessor(){
Department department = new Department("Computer");
professor = new Professor(department , "Salmani");
Course course = new Course("1234" , "AP" , department , professor , 21);
department.addCourse(course);
department.addProfessor(professor);
}
@Test
public void TestGetName(){
assertEquals("Salmani" , professor.getName());
}
@Test
public void TestGetDepartment(){
assertEquals("Computer" , professor.getDepartment().getName());
}
@Test
public void TestgetCourses(){
assertNotNull(professor.getCourses());
}
}
package test;
import com.university.*;
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 UniversityTest {
static University university;
@BeforeAll
public static void CreateUniversity(){
university = new University("AmirKabir");
Department department = new Department("Omran");
Department department1 = new Department("Computer");
Department department2 = new Department("AeroSpace");
university.addDepartment(department);
university.addDepartment(department1);
university.addDepartment(department2);
university.removeDepartment(department);
}
@Test
public void TestaddDepartments(){
assertNotNull(university.getDepartments().length);
}
@Test
public void TestremoveDepartments(){
assertEquals(2 , university.getDepartments().length);
}
@Test
public void TestgetName(){
assertEquals("AmirKabir" , university.getName());
}
}
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