Commit fbde3cbd authored by Roham's avatar Roham

YOLO

parent d13886c8
package com.university; package com.university;
import java.util.ArrayList;
import java.util.List;
public class Course { public class Course {
String ID; String ID;
String name;
Department department;
Professor professor;
List<Student> students;
int credit;
public 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;
this.students = new ArrayList<>();
} }
public String getID(){ public String getID(){
return null; return this.ID;
} }
public Department getDepartment(){ public Department getDepartment(){
return null; return this.department;
} }
public String getName() { public String getName() {
return null; return this.name;
} }
public Student[] getStudents() { public Student[] getStudents() {
return null; Student[] std = new Student[this.students.size()];
for (int i = 0 ; i < this.students.size(); i++)
std[i] = this.students.get(i);
return std;
} }
public Professor getProfessor() { public Professor getProfessor() {
return null; return this.professor;
} }
public int getCredit() { public int getCredit() {
return 0; return this.credit;
} }
public void enrollStudent(Student student){ public void enrollStudent(Student student){
if (student.getDepartment().getName().equals(this.department.getName()))
this.students.add(student);
} }
} }
...@@ -25,7 +25,7 @@ public class Department { ...@@ -25,7 +25,7 @@ public class Department {
} }
public Student[] getStudents(){ public Student[] getStudents(){
return (Student[])this.students.toArray(); return this.students.toArray(new Student[this.students.size()]);
} }
public void removeStudent(Student student){ public void removeStudent(Student student){
...@@ -37,7 +37,7 @@ public class Department { ...@@ -37,7 +37,7 @@ public class Department {
} }
public Course[] getCourses(){ public Course[] getCourses(){
return (Course[])this.courses.toArray(); return this.courses.toArray(new Course[this.courses.size()]);
} }
public void removeCourse(Course course){ public void removeCourse(Course course){
...@@ -49,7 +49,7 @@ public class Department { ...@@ -49,7 +49,7 @@ public class Department {
} }
public Professor[] getProfessors(){ public Professor[] getProfessors(){
return (Professor[])this.professors.toArray(); return this.professors.toArray(new Professor[this.professors.size()]);
} }
public void removeProfessor(Professor professor){ public void removeProfessor(Professor professor){
......
package com.university; package com.university;
public class Student { import java.util.ArrayList;
import java.util.List;
public class Student {
String Name;
String ID;
String major;
Department department;
List<Course> courses;
public 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;
this.courses = new ArrayList<>();
} }
public String getName() { public String getName() {
return null; return this.Name;
} }
public String getID() { public String getID() {
return null; return this.ID;
} }
public String getMajor() { public String getMajor() {
return null; return this.major;
} }
public Department getDepartment() { public Department getDepartment() {
return null; return this.department;
} }
public Course[] getCourses() { public Course[] getCourses() {
return null; Course[] crs = new Course[this.courses.size()];
for(int i = 0 ; i < this.courses.size(); i++)
{
crs[i] = this.courses.get(i);
}
return crs;
} }
public void addCourse(Course course){ public void addCourse(Course course){
this.courses.add(course);
} }
} }
...@@ -6,7 +6,7 @@ import java.util.List; ...@@ -6,7 +6,7 @@ import java.util.List;
public class University { public class University {
List<Department> departments = new ArrayList<>(); List<Department> departments = new ArrayList<>();
public Department[] getDepartments(){ public Department[] getDepartments(){
return (Department[])this.departments.toArray(); return this.departments.toArray(new Department[this.departments.size()]);
} }
public void addDepartment(Department department){ this.departments.add(department);} public void addDepartment(Department department){ this.departments.add(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.*; import static org.junit.jupiter.api.Assertions.*;
class CourseTest { class CourseTest {
static Department department;
static Professor professor;
static Course course;
static Student student;
@BeforeAll
public static void createCourse()
{
department = new Department("Computer");
professor = new Professor(department, "Gholam");
student = new Student("Roham", "1", "Software Eng", department);
course = new Course("1", "AP", department, professor, 0);
course.enrollStudent(student);
}
@Test
public void testCourse()
{
assertEquals("1", course.getID());
assertEquals("AP", course.getName());
assertEquals(department, course.getDepartment());
assertEquals(professor, course.getProfessor());
assertEquals(0, course.getCredit());
assertEquals(student, course.getStudents()[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 DepartmentTest {
static Department department;
static Professor professor;
static Course course;
static Student student;
@BeforeAll
public static void createDepartment()
{
department = new Department("Computer");
professor = new Professor(department, "Gholam");
student = new Student("Roham", "1", "Software Eng", department);
course = new Course("1", "AP", department, professor, 0);
department.addStudent(student);
department.addCourse(course);
department.addProfessor(professor);
}
@Test
public void testDepartment()
{
assertEquals("Computer", department.getName());
assertEquals( course, department.getCourses()[0]);
assertEquals( student, department.getStudents()[0]);
assertEquals(professor, department.getProfessors()[0]);
department.removeCourse(course);
department.removeProfessor(professor);
department.removeStudent(student);
assertEquals( 0, department.getCourses().length);
assertEquals( 0, department.getStudents().length);
assertEquals(0, department.getProfessors().length);
}
}
\ 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 department;
static Professor professor;
static Course course;
static Student student;
@BeforeAll
public static void createProfessor()
{
department = new Department("Computer");
professor = new Professor(department, "Gholam");
student = new Student("Roham", "1", "Software Eng", department);
course = new Course("1", "AP", department, professor, 0);
}
@Test
public void testProfessor()
{
assertEquals("Gholam", professor.getName());
assertEquals(department, professor.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.Test;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
class StudentTest { class StudentTest {
static Student student;
static Department department;
static Course c1;
@BeforeAll
public static void createStudent(){
department = new Department("Computer and IT Eng");
student = new Student("Roham", "1", "Software Eng", department);
c1 = new Course("1", "AP", department, new Professor(department, "Gholam"), 0);
student.addCourse(c1);
}
@Test
public void testStudentGetName(){
assertEquals("Roham", student.getName());
assertEquals("1", student.getID());
assertEquals("Software Eng", student.getMajor());
assertEquals(department, student.getDepartment());
assertEquals(c1, student.getCourses()[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 department;
static University university;
@BeforeAll
public static void createUniversity() {
department = new Department("Computer");
university = new University();
university.addDepartment(department);
}
@Test
public void testUniversity() {
assertEquals(department, university.getDepartments()[0]);
university.removeDepartment(department);
assertEquals(0, university.getDepartments().length);
}
}
\ 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