Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
Lab6
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
9731050
Lab6
Commits
1ab10fd8
Commit
1ab10fd8
authored
Apr 14, 2019
by
9731050
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
2th
parent
9b541e20
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
146 additions
and
4 deletions
+146
-4
Course.java
src/com/university/Course.java
+1
-0
Department.java
src/com/university/Department.java
+8
-1
CourseTest.java
src/test/CourseTest.java
+12
-2
DepartmentTest.java
src/test/DepartmentTest.java
+38
-0
ProfessorTest.java
src/test/ProfessorTest.java
+25
-0
StudentTest.java
src/test/StudentTest.java
+38
-0
UniversityTest.java
src/test/UniversityTest.java
+24
-1
No files found.
src/com/university/Course.java
View file @
1ab10fd8
...
@@ -43,6 +43,7 @@ private ArrayList<Student>students;
...
@@ -43,6 +43,7 @@ private ArrayList<Student>students;
}
}
public
void
enrollStudent
(
Student
student
){
public
void
enrollStudent
(
Student
student
){
if
(
student
.
getDepartment
().
getName
().
compareTo
(
getDepartment
().
getName
())==
0
)
students
.
add
(
student
);
students
.
add
(
student
);
}
}
...
...
src/com/university/Department.java
View file @
1ab10fd8
...
@@ -7,6 +7,7 @@ public class Department {
...
@@ -7,6 +7,7 @@ public class Department {
private
ArrayList
<
Student
>
students
;
private
ArrayList
<
Student
>
students
;
private
ArrayList
<
Course
>
courses
;
private
ArrayList
<
Course
>
courses
;
private
ArrayList
<
Professor
>
professors
;
private
ArrayList
<
Professor
>
professors
;
public
Department
(
String
name
)
{
public
Department
(
String
name
)
{
this
.
name
=
name
;
this
.
name
=
name
;
students
=
new
ArrayList
<
Student
>();
students
=
new
ArrayList
<
Student
>();
...
@@ -18,6 +19,7 @@ public class Department {
...
@@ -18,6 +19,7 @@ public class Department {
}
}
public
void
addStudent
(
Student
student
){
public
void
addStudent
(
Student
student
){
if
(
getName
().
compareTo
(
student
.
getDepartment
().
getName
())==
0
)
students
.
add
(
student
);
students
.
add
(
student
);
}
}
...
@@ -26,10 +28,12 @@ public class Department {
...
@@ -26,10 +28,12 @@ public class Department {
}
}
public
void
removeStudent
(
Student
student
){
public
void
removeStudent
(
Student
student
){
if
(
student
.
getDepartment
().
getName
().
compareTo
(
getName
())==
0
)
students
.
remove
(
student
);
students
.
remove
(
student
);
}
}
public
void
addCourse
(
Course
course
){
public
void
addCourse
(
Course
course
){
if
(
getName
().
compareTo
(
course
.
getDepartment
().
getName
())==
0
)
courses
.
add
(
course
);
courses
.
add
(
course
);
}
}
...
@@ -38,10 +42,12 @@ public class Department {
...
@@ -38,10 +42,12 @@ public class Department {
}
}
public
void
removeCourse
(
Course
course
){
public
void
removeCourse
(
Course
course
){
if
(
getName
().
compareTo
(
course
.
getDepartment
().
getName
())==
0
)
courses
.
remove
(
course
);
courses
.
remove
(
course
);
}
}
public
void
addProfessor
(
Professor
professor
){
public
void
addProfessor
(
Professor
professor
){
if
(
getName
().
compareTo
(
professor
.
getDepartment
().
getName
())==
0
)
professors
.
add
(
professor
);
professors
.
add
(
professor
);
}
}
...
@@ -50,6 +56,7 @@ public class Department {
...
@@ -50,6 +56,7 @@ public class Department {
}
}
public
void
removeProfessor
(
Professor
professor
){
public
void
removeProfessor
(
Professor
professor
){
if
(
getName
().
compareTo
(
professor
.
getDepartment
().
getName
())==
0
)
professors
.
remove
(
professor
);
professors
.
remove
(
professor
);
}
}
...
...
src/test/CourseTest.java
View file @
1ab10fd8
...
@@ -7,28 +7,38 @@ import com.university.Student;
...
@@ -7,28 +7,38 @@ import com.university.Student;
import
org.junit.jupiter.api.BeforeAll
;
import
org.junit.jupiter.api.BeforeAll
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
java.util.ArrayList
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
public
class
CourseTest
{
public
class
CourseTest
{
static
Department
department
;
static
Department
department
;
static
Student
student
;
static
Student
student
,
s2
;
static
Course
course
;
static
Course
course
;
static
Professor
professor
;
static
Professor
professor
;
static
ArrayList
<
Student
>
students
;
@BeforeAll
@BeforeAll
public
static
void
creatStudent
()
public
static
void
creatStudent
()
{
{
students
=
new
ArrayList
<>();
department
=
new
Department
(
"abc"
);
department
=
new
Department
(
"abc"
);
professor
=
new
Professor
(
department
,
"kz"
);
professor
=
new
Professor
(
department
,
"kz"
);
course
=
new
Course
(
"123"
,
"math"
,
department
,
professor
,
3
);
course
=
new
Course
(
"123"
,
"math"
,
department
,
professor
,
3
);
student
=
new
Student
(
"ali"
,
"1234"
,
"abc"
,
department
);
student
=
new
Student
(
"ali"
,
"1234"
,
"abc"
,
department
);
s2
=
new
Student
(
"mohammad"
,
"1235"
,
"b"
,
new
Department
(
"abd"
));
course
.
enrollStudent
(
s2
);
course
.
enrollStudent
(
student
);
course
.
enrollStudent
(
student
);
for
(
int
i
=
0
;
i
<
course
.
getStudents
().
size
();
i
++)
students
.
add
(
course
.
getStudents
().
get
(
i
));
}
}
@Test
@Test
public
void
Test
(){
public
void
Test
(){
assertEquals
(
"math"
,
course
.
getName
());
assertEquals
(
"math"
,
course
.
getName
());
assertEquals
(
"123"
,
course
.
getID
());
assertEquals
(
"123"
,
course
.
getID
());
assertEquals
(
department
,
course
.
getDepartment
());
assertEquals
(
professor
,
course
.
getProfessor
());
assertEquals
(
professor
,
course
.
getProfessor
());
assertEquals
(
3
,
course
.
getCredit
());
assertEquals
(
3
,
course
.
getCredit
());
assertEquals
(
students
,
course
.
getStudents
());
}
}
}
}
src/test/DepartmentTest.java
View file @
1ab10fd8
package
test
;
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
.
assertEquals
;
public
class
DepartmentTest
{
public
class
DepartmentTest
{
static
Department
department
;
static
Student
student
;
static
Course
course
;
static
Professor
professor
;
@BeforeAll
public
static
void
creatStudent
()
{
department
=
new
Department
(
"abc"
);
professor
=
new
Professor
(
department
,
"kz"
);
course
=
new
Course
(
"123"
,
"math"
,
department
,
professor
,
3
);
student
=
new
Student
(
"ali"
,
"1234"
,
"abc"
,
department
);
department
.
addCourse
(
course
);
department
.
addProfessor
(
professor
);
department
.
addStudent
(
student
);
}
@Test
public
void
Test
(){
assertEquals
(
"abc"
,
department
.
getName
());
assertEquals
(
professor
,
department
.
getProfessors
().
get
(
0
));
assertEquals
(
course
,
department
.
getCourses
().
get
(
0
));
assertEquals
(
student
,
department
.
getStudents
().
get
(
0
));
department
.
removeCourse
(
course
);
department
.
removeProfessor
(
professor
);
department
.
removeStudent
(
student
);
assertEquals
(
0
,
department
.
getProfessors
().
get
(
0
));
assertEquals
(
0
,
department
.
getCourses
().
get
(
0
));
assertEquals
(
0
,
department
.
getStudents
().
get
(
0
));
}
}
}
src/test/ProfessorTest.java
View file @
1ab10fd8
package
test
;
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
.
assertEquals
;
public
class
ProfessorTest
{
public
class
ProfessorTest
{
static
Department
department
;
static
Student
student
;
static
Course
course
;
static
Professor
professor
;
@BeforeAll
public
static
void
creatStudent
()
{
department
=
new
Department
(
"abc"
);
professor
=
new
Professor
(
department
,
"kz"
);
}
@Test
public
void
Test
(){
assertEquals
(
department
,
professor
.
getDepartment
());
assertEquals
(
"kz"
,
professor
.
getName
());
}
}
}
src/test/StudentTest.java
View file @
1ab10fd8
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
java.util.ArrayList
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
class
StudentTest
{
class
StudentTest
{
static
Department
department
;
static
Student
student
;
static
Course
course
,
c
;
static
Professor
professor
;
static
ArrayList
<
Course
>
courses
;
@BeforeAll
public
static
void
creatStudent
()
{
courses
=
new
ArrayList
<>();
department
=
new
Department
(
"abc"
);
professor
=
new
Professor
(
department
,
"kz"
);
student
=
new
Student
(
"ali"
,
"1234"
,
"aaa"
,
department
);
course
=
new
Course
(
"123"
,
"math"
,
department
,
professor
,
3
);
c
=
new
Course
(
"12"
,
"Mohammad"
,
department
,
professor
,
2
);
student
.
addCourse
(
course
);
courses
.
add
(
course
);
student
.
addCourse
(
c
);
courses
.
add
(
c
);
}
@Test
public
void
Test
(){
assertEquals
(
"ali"
,
student
.
getName
());
assertEquals
(
"1234"
,
student
.
getID
());
assertEquals
(
"aaa"
,
student
.
getMajor
());
assertEquals
(
department
,
student
.
getDepartment
());
assertEquals
(
courses
,
student
.
getCourses
());
}
}
}
\ No newline at end of file
src/test/UniversityTest.java
View file @
1ab10fd8
package
test
;
package
test
;
public
class
UnivercityTest
{
import
com.university.*
;
import
org.junit.jupiter.api.BeforeAll
;
import
org.junit.jupiter.api.Test
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
public
class
UniversityTest
{
static
Department
department
;
static
Student
student
;
static
Course
course
;
static
Professor
professor
;
static
University
university
;
@BeforeAll
public
static
void
creatStudent
()
{
department
=
new
Department
(
"abc"
);
university
.
addDepartment
(
department
);
}
@Test
public
void
Test
(){
assertEquals
(
department
,
university
.
getDepartments
().
get
(
0
));
university
.
removeDepartment
(
department
);
assertEquals
(
0
,
university
.
getDepartments
().
get
(
0
));
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment