Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
lab6_deadline
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
9531304
lab6_deadline
Commits
e41e1d73
Commit
e41e1d73
authored
May 24, 2019
by
9531304
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding second part
parent
c47796bc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
133 additions
and
5 deletions
+133
-5
Course.java
src/com/university/Course.java
+2
-1
Department.java
src/com/university/Department.java
+35
-4
CourseTest.java
src/test/CourseTest.java
+73
-0
DepartmentTest.java
src/test/DepartmentTest.java
+23
-0
No files found.
src/com/university/Course.java
View file @
e41e1d73
...
@@ -44,7 +44,8 @@ public class Course {
...
@@ -44,7 +44,8 @@ public class Course {
}
}
public
void
enrollStudent
(
Student
student
){
public
void
enrollStudent
(
Student
student
){
stds
.
add
(
student
);
if
(
student
.
getDepartment
()
==
this
.
dpart
){
stds
.
add
(
student
);}
}
}
...
...
src/com/university/Department.java
View file @
e41e1d73
package
com
.
university
;
package
com
.
university
;
import
java.util.ArrayList
;
public
class
Department
{
public
class
Department
{
private
String
name
;
private
String
name
;
private
ArrayList
<
Student
>
stds
=
new
ArrayList
<
Student
>();
private
Student
[]
students
;
private
ArrayList
<
Course
>
crs
=
new
ArrayList
<
Course
>();
private
Course
[]
courses
;
private
ArrayList
<
Professor
>
prfs
=
new
ArrayList
<
Professor
>();
private
Professor
[]
professors
;
public
Department
(
String
name
)
{
public
Department
(
String
name
)
{
this
.
name
=
name
;
this
.
name
=
name
;
}
}
...
@@ -11,38 +19,61 @@ public class Department {
...
@@ -11,38 +19,61 @@ public class Department {
}
}
public
void
addStudent
(
Student
student
){
public
void
addStudent
(
Student
student
){
if
(
student
.
getDepartment
().
getName
()
==
this
.
name
){
stds
.
add
(
student
);
}
}
}
public
Student
[]
getStudents
(){
public
Student
[]
getStudents
(){
return
null
;
students
=
stds
.
toArray
(
new
Student
[
stds
.
size
()]);
return
students
;
}
}
public
void
removeStudent
(
Student
student
){
public
void
removeStudent
(
Student
student
){
if
(
student
.
getDepartment
().
getName
()
==
this
.
name
){
for
(
Student
std
:
students
){
if
(
std
==
student
)
stds
.
remove
(
student
);}
}
}
}
public
void
addCourse
(
Course
course
){
public
void
addCourse
(
Course
course
){
if
(
course
.
getDepartment
().
getName
()
==
this
.
name
)
{
crs
.
add
(
course
);
}
}
}
public
Course
[]
getCourses
(){
public
Course
[]
getCourses
(){
return
null
;
courses
=
crs
.
toArray
(
new
Course
[
crs
.
size
()]);
return
courses
;
}
}
public
void
removeCourse
(
Course
course
){
public
void
removeCourse
(
Course
course
){
crs
.
remove
(
course
);
}
}
public
void
addProfessor
(
Professor
student
){
public
void
addProfessor
(
Professor
professor
){
if
(
professor
.
getDepartment
().
getName
()
==
this
.
name
){
prfs
.
add
(
professor
);
}
}
}
public
Professor
[]
getProfessors
(){
public
Professor
[]
getProfessors
(){
return
null
;
professors
=
prfs
.
toArray
(
new
Professor
[
prfs
.
size
()]);
return
professors
;
}
}
public
void
removeProfessor
(
Professor
professor
){
public
void
removeProfessor
(
Professor
professor
){
for
(
Professor
pfs
:
prfs
){
if
(
pfs
==
professor
){
prfs
.
remove
(
professor
);
}
}
}
}
...
...
src/test/CourseTest.java
0 → 100644
View file @
e41e1d73
package
test
;
import
com.university.Student
;
import
com.university.Course
;
import
com.university.Professor
;
import
com.university.Department
;
import
org.junit.jupiter.api.BeforeAll
;
import
org.junit.jupiter.api.Test
;
import
static
junit
.
framework
.
TestCase
.
assertEquals
;
import
static
junit
.
framework
.
TestCase
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNotEquals
;
public
class
CourseTest
{
static
Course
course
;
@BeforeAll
public
static
void
createCourse
(){
Department
department
=
new
Department
(
"Computer"
);
Department
department1
=
new
Department
(
"Civil"
);
Professor
professor
=
new
Professor
(
department
,
"HajMohammadi"
);
course
=
new
Course
(
"2122"
,
"EnteghaleHararat"
,
department
,
professor
,
21
);
Student
std1
=
new
Student
(
"Mohammad"
,
"9525080"
,
"Omran"
,
department1
);
course
.
enrollStudent
(
std1
);
Student
std2
=
new
Student
(
"Karim"
,
"9321098"
,
"Electricity"
,
department
);
course
.
enrollStudent
(
std2
);
Student
std3
=
new
Student
(
"ali"
,
"9321088"
,
"Electricity"
,
department
);
course
.
enrollStudent
(
std3
);
Student
std4
=
new
Student
(
"reza"
,
"9321078"
,
"Electricity"
,
department
);
course
.
enrollStudent
(
std4
);
Student
std5
=
new
Student
(
"farzin"
,
"9321098"
,
"Electricity"
,
department
);
course
.
enrollStudent
(
std5
);
Student
std6
=
new
Student
(
"hossein"
,
"9321098"
,
"Electricity"
,
department
);
course
.
enrollStudent
(
std6
);
Student
std7
=
new
Student
(
"nima"
,
"9321098"
,
"Electricity"
,
department
);
course
.
enrollStudent
(
std7
);
Student
std8
=
new
Student
(
"erfan"
,
"9321098"
,
"Electricity"
,
department
);
course
.
enrollStudent
(
std8
);
Student
std9
=
new
Student
(
"javad"
,
"9321098"
,
"Electricity"
,
department
);
course
.
enrollStudent
(
std9
);
Student
std10
=
new
Student
(
"arman"
,
"9321098"
,
"Electricity"
,
department
);
course
.
enrollStudent
(
std10
);
Student
[]
stds
=
new
Student
[]{
std1
,
std2
,
std3
,
std4
,
std5
,
std6
,
std7
,
std8
,
std9
,
std10
};
}
@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
());
}
@Test
public
void
testCourseGetEnrollStudents
(){
assertNotEquals
(
1
,
course
.
getStudents
().
length
);
}
@Test
public
void
testCourseEnrollStudents
(){
for
(
Student
std
:
stds
){
}
}
}
src/test/DepartmentTest.java
0 → 100644
View file @
e41e1d73
package
test
;
import
com.university.Student
;
import
com.university.Professor
;
import
com.university.Department
;
import
com.university.Course
;
import
org.junit.jupiter.api.BeforeAll
;
import
org.junit.jupiter.api.Test
;
import
static
junit
.
framework
.
TestCase
.
assertEquals
;
import
static
junit
.
framework
.
TestCase
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNotEquals
;
public
class
DepartmentTest
{
static
Department
department
;
@BeforeAll
public
static
void
CreateDepartment
(){
department
=
new
Department
(
"Computer"
);
Student
student
=
new
Student
(
"Ali"
,
"3212"
,
"Computer"
,
department
);
}
}
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