Commit ffea8b5b authored by Ali Shakoori's avatar Ali Shakoori

final commit from two dead men

parents
Pipeline #457 failed with stages
# lab 6
## Fixed lab6
### shamel rr :)))
* dorood
* rr
* takmile rr
* debugging
* kheili debugging
* hatta bishtar debugging
* infinitive debugging
* and we are dead now
* bye bye from another world :)
- made by Ali and Milad
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" scope="TEST">
<library name="JUnit5.3">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/junit-jupiter-api-5.5.0-M1.jar!/" />
<root url="jar://$MODULE_DIR$/lib/apiguardian-api-1.0.0.jar!/" />
<root url="jar://$MODULE_DIR$/lib/opentest4j-1.1.1.jar!/" />
<root url="jar://$MODULE_DIR$/lib/junit-platform-commons-1.5.0-M1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/junit-jupiter-api-5.5.0-M1.jar!/" />
<root url="jar://$MODULE_DIR$/lib/apiguardian-api-1.0.0.jar!/" />
<root url="jar://$MODULE_DIR$/lib/opentest4j-1.1.1.jar!/" />
<root url="jar://$MODULE_DIR$/lib/junit-platform-commons-1.5.0-M1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
\ No newline at end of file
package com.university;
import java.util.ArrayList;
public class Course {
String ID;
String name;
Department department;
Professor professor;
int credit;
ArrayList<Student> stu = new ArrayList<>();
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 ID;
}
public Department getDepartment(){
return department;
}
public String getName() {
return name;
}
public Student[] getStudents() {
Student[] studentArray = new Student[stu.size()];
if(stu.size() == 0){
return null;
}else {
return stu.toArray(studentArray);
}
}
public Professor getProfessor() {
return professor;
}
public int getCredit() {
return credit;
}
public void enrollStudent(Student student){
if(student.getDepartment().getName().equals(this.getDepartment().getName()))
stu.add(student);
}
}
package com.university;
import java.util.ArrayList;
public class Department {
String name;
ArrayList<Student> stuu = new ArrayList<>();
ArrayList<Course> courses = new ArrayList<>();
ArrayList<Professor> professors = new ArrayList<>();
public Department(String name) {
this.name = name;
}
public String getName(){
return name;
}
public void addStudent(Student student){
if(student.getDepartment().getName().equals(this.getName()))
stuu.add(student);
}
public Student[] getStudents(){
Student[] studentArray = new Student[stuu.size()];
if(stuu.size() == 0){
return null;
}else {
return stuu.toArray(studentArray);
}
}
public void removeStudent(Student student){
if(student.getDepartment().getName().equals(this.getName()))
stuu.remove(student);
}
public void addCourse(Course course){
if(course.getDepartment().getName().equals(this.getName())){
courses.add(course);
}
}
public Course[] getCourses(){
Course[] myCourse = new Course[courses.size()];
if(courses.size() == 0){
return null;
}else {
return courses.toArray(myCourse);
}
}
public void removeCourse(Course course){
if(course.getDepartment().getName().equals(this.getName())){
courses.remove(course);
}
}
public void addProfessor(Professor student){
if(student.getDepartment().getName().equals(this.getName())){
professors.add(student);
}
}
public Professor[] getProfessors()
{
Professor[] myProfessor = new Professor[professors.size()];
if(professors.size() == 0){
return null;
}else {
return professors.toArray(myProfessor);
}
}
public void removeProfessor(Professor professor){
if(professor.getDepartment().getName().equals(this.getName())){
professors.add(professor);
}
}
}
package com.university;
import java.util.ArrayList;
public class Professor {
Department department;
String name;
ArrayList<Course> proCourse = new ArrayList<>();
public Professor(Department department, String name) {
this.department = department;
this.name = name;
}
public Department getDepartment() {
return department;
}
public String getName() {
return name;
}
public Course[] getCourses() {
for (Course aCourse:department.getCourses()) {
if(aCourse.getProfessor().getName().equals(this.getName())){
proCourse.add(aCourse);
}
}
Course[] courseArray = new Course[proCourse.size()];
if(proCourse.size() == 0){
return null;
}else {
return proCourse.toArray(courseArray);
}
}
}
package com.university;
import java.util.ArrayList;
import java.util.Collections;
public class Student {
String name;
String ID;
String major;
Department department;
ArrayList<Course> a = 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 name;
}
public String getID() {
return ID;
}
public String getMajor() {
return major;
}
public Department getDepartment() {
return department;
}
public Course[] getCourses() {
Course[] b = new Course[a.size()];
if(a.size() == 0){
return null;
}else {
return a.toArray(b);
}
}
public void addCourse(Course course){
if(course.getDepartment().getName().equals(this.getDepartment().getName())){
a.add(course);
}
}
}
package com.university;
import java.util.ArrayList;
public class University {
ArrayList<Department> departments = new ArrayList<>();
public Department[] getDepartments(){
Department[] depArray = new Department[departments.size()];
if(departments.size() == 0){
return null;
}
return departments.toArray(depArray);
}
public void addDepartment(Department department){
departments.add(department);
}
public void removeDepartment(Department department){
departments.remove(department);
}
}
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 StudentTest {
// static Student student;
// static Course course;
// static Department chem ;
//
// @BeforeAll
// public static void creatStudentTest() {
// student = new Student("Milad" , "9731007" , "Com" , new Department("Com"));
// course = new Course("1" , "AP" , new Department("Com") , new Professor(new Department("Com") , "Farzin"), 0 );
// course.enrollStudent(student);
// }
//
// @Test
// public void StudentNameTest(){
// assertEquals("Milad" , student.getName());
// }
//
// @Test
// public void courseTest(){
// assertEquals("1" , course.getID());
// assertNull(course.getStudents());
// }
//
//// @Test
//// public void DepartmentTest(){
//// assertEquals();
//// }
//
//}
public class StudentTest {
static Student student;
static Student student2;
static Department department;
static Department department2;
static Professor professor;
static Professor professor2;
static Course c1;
static Course c2;
static University uni;
@BeforeAll
public static void createStudent(){
department = new Department("Computer and IT Eng");
department2 = new Department("Chemistry");
student = new Student("Alireza", "1234", "Software Eng", department);
student2 = new Student("Milad" , "1235" , "Chem" , department2);
professor = new Professor(department , "Kalbasi");
professor2 = new Professor(department2 , "Noshad");
c1 = new Course("2" , "Chem" , department2 , professor , 200 );
c2 = new Course("1" , "C" , department , professor , 200 );
uni = new University();
}
@Test
public void testStudentGetName(){
assertEquals("Alireza", student.getName());
}
@Test
public void testStudentID(){
assertEquals("1234" , student.getID());
}
@Test
public void testStudentMajor(){
assertEquals("Software Eng" , student.getMajor());
}
@Test
public void testAddCourse(){
student.addCourse(c1);
assertNull(student.getCourses());
student.addCourse(c2);
assertNotNull(student.getCourses());
}
@Test
public void testCourseID(){
assertEquals("2" , c1.getID());
}
@Test
public void testGetDepartment(){
assertNotNull(c1.getDepartment());
}
@Test
public void testCourseGetName(){
assertEquals("Chem" , c1.getName());
}
@Test
public void testCourseGetProfessor(){
assertNotNull(c1.getProfessor());
}
@Test
public void testEnrollStudent(){
c2.enrollStudent(student2);
assertNull(c1.getStudents());
c2.enrollStudent(student);
assertNotNull(c2.getStudents());
}
@Test
public void testDepartmentAddStudent(){
department.addStudent(student2);
assertNull(department.getStudents());
department.addStudent(student);
assertNotNull(department.getStudents());
}
@Test
public void testDepartmentRemoveStudent(){
department.removeStudent(student2);
assertNotNull(department.getStudents());
department.removeStudent(student);
assertNull(department.getStudents());
}
@Test
public void testDepartmentGetName(){
assertEquals("Computer and IT Eng" , department.getName());
}
@Test
public void testDepartmentAddCourse(){
department.removeCourse(c2);
department.addCourse(c1);
assertNull(department.getCourses());
department.addCourse(c2);
assertNotNull(department.getCourses());
}
@Test
public void testDepartmentRemove(){
department.removeCourse(c1);
assertNotNull(department.getCourses());
department.removeCourse(c2);
assertNull(department.getCourses());
}
@Test
public void testDepartmentAddProfessor(){
department.addProfessor(professor2);
assertNull(department.getProfessors());
department.addProfessor(professor);
assertNotNull(department.getProfessors());
}
@Test
public void testDepartmentGetCourse(){
assertNotNull(department.getCourses());
}
@Test
public void testProfessorGetDepartment(){
assertEquals(department , professor.getDepartment());
}
@Test
public void testProfessorName(){
assertEquals("Kalbasi" ,professor.getName());
}
@Test
public void testProfessorGetCourse(){
department.addCourse(c2);
assertNotNull(professor.getCourses());
}
@Test
public void testAddDepartmentUniversity(){
assertNull(uni.getDepartments());
uni.addDepartment(department);
assertNotNull(uni.getDepartments());
}
}
\ 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