Commit 6934e19f authored by 9731044's avatar 9731044

add

parents
Pipeline #461 failed with stages
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path=""/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path=""/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>lab-6</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
package com.university;
import java.util.ArrayList;
public class Course {
private String ID;
private String name;
private Department department;
private Professor professor;
private int credit;
ArrayList<Student> students = new ArrayList<>();
public Course(String ID, String name, Department department, Professor professor, int credit) {
this.credit=credit;
this.department=department;
this.ID=ID;
this.name=name;
this.professor=professor;
}
public String getID(){
return this.ID;
}
public Department getDepartment(){
return this.department;
}
public String getName() {
return this.name;
}
public Student[] getStudents() {
Student[] arr = new Student[students.size()];
return students.toArray(arr);
}
public Professor getProfessor() {
return this.professor;
}
public int getCredit() {
return this.credit;
}
public void enrollStudent(Student student){
if(student.getDepartment()== this.department)
students.add(student);
}
}
package com.university;
import java.util.ArrayList;
public class Department {
private String name;
private ArrayList<Student> students = new ArrayList<>();
private ArrayList<Course> courses = new ArrayList<>();
private ArrayList<Professor> professors = new ArrayList<>();
public Department(String name) {
this.name = name;
}
public String getName(){
return this.name;
}
public void addStudent(Student student){
if(student.getDepartment() == this)
students.add(student);
}
public Student[] getStudents(){
Student[] arr = new Student[students.size()];
return students.toArray(arr);
}
public void removeStudent(Student student){
if(student.getDepartment() != this)
return;
for(int i=0;i<students.size();i++) {
if(students.get(i) == student) {
students.remove(student);
break;
}
}
}
public void addCourse(Course course){
if(course.getDepartment() == this)
courses.add(course);
}
public Course[] getCourses(){
Course[] arr = new Course[courses.size()];
return courses.toArray(arr);
}
public void removeCourse(Course course){
if(course.getDepartment() != this)
return;
for(int i=0;i<courses.size();i++)
if(courses.get(i) == course) {
courses.remove(course);
break;
}
}
public void addProfessor(Professor professor){
if(professor.getDepartment() == this)
professors.add(professor);
if(professor.getDepartment() != this)
return;
}
public Professor[] getProfessors(){
Professor[] arr = new Professor[professors.size()];
return professors.toArray(arr);
}
public void removeProfessor(Professor professor){
if(professor.getDepartment() != this)
return;
for(int i=0;i<professors.size();i++) {
if(professors.get(i) == professor) {
professors.remove(professor);
break;
}
}
}
}
package com.university;
public class Professor {
private Department department;
private String name;
private Course[] courses;
public Professor(Department department, String name) {
this.department=department;
this.name=name;
courses = new Course[1];
}
public Department getDepartment() {
return this.department;
}
public String getName() {
return this.name;
}
public Course[] getCourses() {
return courses;
}
}
package com.university;
import java.util.ArrayList;
public class Student {
private String name;
private String ID;
private String major;
private Department department;
private ArrayList<Course> courses = new ArrayList<>();
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 this.name;
}
public String getMajor() {
return this.name;
}
public Department getDepartment() {
return this.department;
}
public Course[] getCourses() {
Course[] arr = new Course[courses.size()];
return courses.toArray(arr);
}
public void addCourse(Course course){
if(course != null)
courses.add(course);
}
}
package com.university;
import java.util.ArrayList;
public class University {
ArrayList<Department> departments = new ArrayList<>();
public Department[] getDepartments(){
Department[] arr = new Department[departments.size()];
return departments.toArray(arr);
}
public void addDepartment(Department department){
departments.add(department);
}
public void removeDepartment(Department department){
for(int i=0;i<departments.size();i++)
if(departments.get(i) == department)
departments.remove(department);
}
}
package test;
import static org.junit.Assert.assertNotNull;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import com.university.Course;
import com.university.Department;
import com.university.Professor;
class CourseTest {
static Professor professor;
static Department department;
static Course course;
@BeforeAll
public static void createCourse(){
department = new Department("Computer and IT Eng");
professor = new Professor(department, "Kalbasi");
course = new Course("1","Advanced Programming",department,professor,3);
}
@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());
}
}
package test;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import com.university.Department;
import com.university.Professor;
class ProfessorTest {
static Professor professor;
static Department department;
@BeforeAll
public static void createProfessor() {
department = new Department("Computer and IT Eng");
professor=new Professor(department,"Kalbasi");
}
@Test
public void testProfessorGetName() {
assertNotNull(professor.getName());
}
@Test
public void testProfessorGetDepartment() {
assertNotNull(professor.getDepartment());
}
}
package test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import com.university.Department;
import com.university.Student;
public class StudentTests {
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);
}
@Test
public void testStudentGetID() {
assertNotNull(student.getID());
}
@Test
public void testStudentGetDepartment() {
assertNotNull(student.getDepartment());
}
@Test
public void testStudentGetMajor() {
assertNotNull(student.getMajor());
}
}
package test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import com.university.Department;
class TestDepartment {
static Department department;
@BeforeAll
public static void createDepartment() {
department=new Department("Computer and IT Eng");
}
@Test
public void testDepartmentGetStudents() {
assertNotNull(department.getStudents());
}
@Test
public void testDepartmentGetCourses() {
assertNotNull(department.getCourses());
}
@Test
public void testDepartmentGetProfessors() {
assertNotNull(department.getProfessors());
}
}
package test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import com.university.University;
class UniversityTest {
static University university;
@BeforeAll
public static void createUniversity() {
university = new University();
}
}
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