Commit 605157a3 authored by Amirhosein Rajabpour's avatar Amirhosein Rajabpour

first commit

parent 966f3f42
package com.university;
import java.util.ArrayList;
public class Course {
String ID;
String name;
Department department;
Professor professor;
int credit;
public Course(String ID, String name, Department department, Professor professor, int credit) {
this.ID = ID;
this.name = name;
this.department = department;
this.professor = professor;
this.credit = credit;
}
public String getID(){
return this.ID;
}
public Department getDepartment(){
return department;
}
public String getName() {
return name;
}
public ArrayList<Student> getStudents() {
return students;
}
public Professor getProfessor() {
return professor;
}
public int getCredit() {
return credit;
}
ArrayList<Student> students = new ArrayList<>();
public void enrollStudent(Student student){
students.add(student);
}
}
package com.university;
import java.util.ArrayList;
public class Department {
String name;
public Department(String name) {
this.name = name;
}
public String getName(){
return this.name;
}
ArrayList<Student> depStudent = new ArrayList<>();
ArrayList<Course> depCourses = new ArrayList<>();
ArrayList<Professor> depProfessor = new ArrayList<>();
public void addStudent(Student student){
depStudent.add(student);
}
public ArrayList<Student> getStudents(){
return depStudent;
}
public void removeStudent(Student student){
depStudent.remove(student);
}
public void addCourse(Course course){
depCourses.add(course);
}
public ArrayList<Course> getCourses(){
return depCourses;
}
public void removeCourse(Course course){
depCourses.remove(course);
}
public void addProfessor(Professor prof){
depProfessor.add(prof);
}
public ArrayList<Professor> getProfessors(){
return depProfessor;
}
public void removeProfessor(Professor professor){
depProfessor.remove(professor);
}
}
package com.university;
import java.util.ArrayList;
public class Professor {
Department department;
String name;
public Professor(Department department, String name) {
this.department = department;
this.name = name;
}
public Department getDepartment() {
return this.department;
}
public String getName() {
return this.name;
}
ArrayList<Course> profCourse = new ArrayList<>();
public ArrayList<Course> getCourses() {
return profCourse;
}
}
package com.university;
import java.util.ArrayList;
public class Student {
String name;
String ID;
String major;
Department department;
public Student(String name, String ID, String major, Department department) {
this.name = name;
this.ID = ID;
this.major = major;
this.department = department;
}
public String getName() {
return this.name;
}
public String getID() {
return ID;
}
public String getMajor() {
return major;
}
public Department getDepartment() {
return department;
}
ArrayList<Course> courses= new ArrayList<Course>();
public ArrayList getCourses() {
return courses;
}
public void addCourse(Course course){
courses.add(course);
}
}
package com.university;
import java.util.ArrayList;
public class University {
ArrayList<Department> uniDep = new ArrayList<>();
public ArrayList<Department> getDepartments(){
return uniDep;
}
public void addDepartment(Department department){
uniDep.add(department);
}
public void removeDepartment(Department department){
uniDep.remove(department);
}
}
package test;
import com.university.Course;
import com.university.Department;
import com.university.Professor;
import com.university.Student;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class CourseTest {
static Department dep;
static Professor prof;
static Course myCourse;
static Student st;
@BeforeAll
public static void createCourse(){
dep = new Department("comp");
prof = new Professor(dep, "ali");
myCourse = new Course("123","karga",dep,prof,5);
st = new Student("Ali","1234","ce",dep);
}
@Test
public void testCourse(){
assertEquals("karga",myCourse.getName());
assertEquals("123",myCourse.getID());
assertEquals(5,myCourse.getCredit());
assertEquals(dep,myCourse.getDepartment());
assertEquals(prof,myCourse.getProfessor());
// assertEquals(st,myCourse.getStudents());
}
}
\ No newline at end of file
package test;
import com.university.Course;
import com.university.Department;
import com.university.Professor;
import com.university.Student;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class DepartmentTest {
static Department myDep;
static Student s1;
static Course myCourse;
static Professor prof;
@BeforeAll
public static void createDepartment(){
myDep = new Department("ce");
s1 = new Student("Ali","1234","ce",myDep);
myCourse = new Course("123","az",myDep,prof,123);
prof = new Professor(myDep, "ali");
myDep.addCourse(myCourse);
myDep.addProfessor(prof);
myDep.addStudent(s1);
}
@Test
public void check(){
assertEquals("ce",myDep.getName());
assertEquals(myCourse,myDep.getCourses().get(0));
assertEquals(prof,myDep.getProfessors().get(0));
assertEquals(s1,myDep.getStudents().get(0));
myDep.removeCourse(myCourse);
myDep.removeProfessor(prof);
myDep.removeStudent(s1);
assertNull(myDep.getCourses());
assertEquals(0,myDep.getStudents().get(0));
assertEquals(0,myDep.getProfessors().get(0));
}
}
\ No newline at end of file
package test;
import com.university.Course;
import com.university.Department;
import com.university.Professor;
import com.university.Student;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class ProfessorTest {
static Department myDep;
static Student s1;
static Course myCourse;
static Professor prof;
@BeforeAll
public static void createProfesor(){
myDep = new Department("ce");
s1 = new Student("Ali","1234","ce",myDep);
myCourse = new Course("123","az",myDep,prof,123);
prof = new Professor(myDep, "ali");
myDep.addCourse(myCourse);
myDep.addProfessor(prof);
myDep.addStudent(s1);
}
@Test
public void testProfesor(){
assertEquals("ali",prof.getName());
assertEquals(myDep,prof.getDepartment());
}
}
\ No newline at end of file
package test;
import com.university.Course;
import com.university.Department;
import com.university.Professor;
import com.university.Student;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class StudentTest {
static Student s1;
static Department dep1;
static Course myCourse;
static Professor prof;
@BeforeAll
public static void creatStudent(){
dep1 = new Department("aut");
s1 = new Student("Ali","1234","ce",dep1);
myCourse = new Course("123","az",dep1,prof,123);
s1.addCourse(myCourse);
}
@Test @DisplayName("name check")
public void testName(){
assertEquals("Ali",s1.getName());
assertEquals("1234",s1.getID());
assertEquals("ce",s1.getMajor());
assertEquals(dep1,s1.getDepartment());
assertEquals(myCourse,s1.getCourses().get(0));
}
}
\ No newline at end of file
package test;
import com.university.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class UniversityTest {
static Department myDep;
static Student s1;
static Course myCourse;
static Professor prof;
static University u;
@BeforeAll
public static void createProfesor(){
myDep = new Department("ce");
u.addDepartment(myDep);
}
@Test
public void tetsUniversity(){
assertEquals(myDep,u.getDepartments());
u.removeDepartment(myDep);
assertEquals(0,u.getDepartments().get(0));
}
}
\ No newline at end of file
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