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
ff41411e
Commit
ff41411e
authored
May 24, 2019
by
9531304
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Complete
parent
e41e1d73
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
166 additions
and
58 deletions
+166
-58
Course.java
src/com/university/Course.java
+1
-1
Department.java
src/com/university/Department.java
+6
-7
Professor.java
src/com/university/Professor.java
+10
-2
StudnetTest.java
src/com/university/StudnetTest.java
+0
-32
University.java
src/com/university/University.java
+23
-3
test.java
src/com/university/test.java
+0
-10
CourseTest.java
src/test/CourseTest.java
+0
-2
DepartmentTest.java
src/test/DepartmentTest.java
+51
-1
TestProfessor.java
src/test/TestProfessor.java
+35
-0
UniversityTest.java
src/test/UniversityTest.java
+40
-0
No files found.
src/com/university/Course.java
View file @
ff41411e
...
...
@@ -44,7 +44,7 @@ public class Course {
}
public
void
enrollStudent
(
Student
student
){
if
(
student
.
getDepartment
()
==
this
.
dpart
){
if
(
student
.
getDepartment
()
==
this
.
dpart
&&
stds
.
indexOf
(
student
)
>=
0
){
stds
.
add
(
student
);}
}
...
...
src/com/university/Department.java
View file @
ff41411e
...
...
@@ -6,7 +6,7 @@ public class Department {
private
String
name
;
private
ArrayList
<
Student
>
stds
=
new
ArrayList
<
Student
>();
private
Student
[]
students
;
p
rivate
ArrayList
<
Course
>
crs
=
new
ArrayList
<
Course
>();
p
ublic
ArrayList
<
Course
>
crs
=
new
ArrayList
<
Course
>();
private
Course
[]
courses
;
private
ArrayList
<
Professor
>
prfs
=
new
ArrayList
<
Professor
>();
private
Professor
[]
professors
;
...
...
@@ -19,8 +19,9 @@ public class Department {
}
public
void
addStudent
(
Student
student
){
if
(
student
.
getDepartment
().
getName
()
==
this
.
name
){
if
(
student
.
getDepartment
().
getName
()
==
this
.
name
&&
stds
.
indexOf
(
student
)
<=
-
1
){
stds
.
add
(
student
);
}
}
...
...
@@ -32,15 +33,13 @@ public class Department {
public
void
removeStudent
(
Student
student
){
if
(
student
.
getDepartment
().
getName
()
==
this
.
name
){
for
(
Student
std
:
students
){
if
(
std
==
student
)
stds
.
remove
(
student
);}
stds
.
remove
(
student
);
}
}
public
void
addCourse
(
Course
course
){
if
(
course
.
getDepartment
().
getName
()
==
this
.
name
)
{
if
(
course
.
getDepartment
().
getName
()
==
this
.
name
&&
crs
.
indexOf
(
course
)
<=
-
1
)
{
crs
.
add
(
course
);
}
...
...
@@ -57,7 +56,7 @@ public class Department {
}
public
void
addProfessor
(
Professor
professor
){
if
(
professor
.
getDepartment
().
getName
()
==
this
.
name
){
if
(
professor
.
getDepartment
().
getName
()
==
this
.
name
&&
prfs
.
indexOf
(
professor
)
<=
-
1
){
prfs
.
add
(
professor
);
}
...
...
src/com/university/Professor.java
View file @
ff41411e
...
...
@@ -5,7 +5,8 @@ import java.util.ArrayList;
public
class
Professor
{
private
String
name
;
private
Department
dpart
;
private
ArrayList
<
Course
>
crs
=
new
ArrayList
<
Course
>();
private
ArrayList
<
Course
>
cors
=
new
ArrayList
<
Course
>();
private
Course
[]
courses
;
public
Professor
(
Department
department
,
String
name
)
{
this
.
name
=
name
;
...
...
@@ -21,6 +22,13 @@ public class Professor {
}
public
Course
[]
getCourses
()
{
return
null
;
for
(
Course
cr
:
dpart
.
crs
){
if
(
cr
.
getProfessor
().
getName
()
==
this
.
name
){
cors
.
add
(
cr
);
}
}
courses
=
cors
.
toArray
(
new
Course
[
cors
.
size
()]);
return
courses
;
}
}
src/com/university/StudnetTest.java
deleted
100644 → 0
View file @
e41e1d73
package
com
.
university
;
import
org.junit.Test
;
import
org.junit.jupiter.api.BeforeAll
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
public
class
StudnetTest
{
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
);
}
}
src/com/university/University.java
View file @
ff41411e
package
com
.
university
;
import
java.util.ArrayList
;
public
class
University
{
private
String
name
;
private
ArrayList
<
Department
>
dprmts
=
new
ArrayList
<
Department
>();
private
Department
[]
departments
;
public
University
(
String
name
){
this
.
name
=
name
;
}
public
String
getName
(){
return
name
;
}
public
Department
[]
getDepartments
(){
return
null
;
departments
=
dprmts
.
toArray
(
new
Department
[
dprmts
.
size
()]);
return
departments
;
}
public
void
addDepartment
(
Department
department
){
}
public
void
addDepartment
(
Department
department
){
if
(
dprmts
.
indexOf
(
department
)<=
-
1
)
dprmts
.
add
(
department
);
}
public
void
removeDepartment
(
Department
department
){
}
public
void
removeDepartment
(
Department
department
){
if
(
dprmts
.
indexOf
(
department
)
>=
0
){
dprmts
.
remove
(
department
);
}
}
}
src/com/university/test.java
deleted
100644 → 0
View file @
e41e1d73
package
com
.
university
;
public
class
test
{
public
static
void
main
(
String
[]
args
){
Department
dp
=
new
Department
(
"amirkabir"
);
Student
st
=
new
Student
(
"Mohammad"
,
"1234"
,
"Mechanic"
,
dp
);
System
.
out
.
println
(
st
.
getName
());
}
}
src/test/CourseTest.java
View file @
ff41411e
...
...
@@ -66,8 +66,6 @@ public class CourseTest {
}
@Test
public
void
testCourseEnrollStudents
(){
for
(
Student
std
:
stds
){
}
}
}
src/test/DepartmentTest.java
View file @
ff41411e
...
...
@@ -12,12 +12,62 @@ import static junit.framework.TestCase.assertNotNull;
import
static
org
.
junit
.
Assert
.
assertNotEquals
;
public
class
DepartmentTest
{
static
Department
department
;
static
Department
department
,
department2
;
@BeforeAll
public
static
void
CreateDepartment
(){
department
=
new
Department
(
"Computer"
);
Student
student
=
new
Student
(
"Ali"
,
"3212"
,
"Computer"
,
department
);
Professor
professor1
=
new
Professor
(
department
,
"salmani"
);
department
.
addStudent
(
student
);
department2
=
new
Department
(
"mechanic"
);
Professor
professor2
=
new
Professor
(
department2
,
"Ohadi"
);
Student
student1
=
new
Student
(
"Mohammad"
,
"9321078"
,
"Mechanic"
,
department2
);
department2
.
addStudent
(
student
);
Student
student2
=
new
Student
(
"Ali"
,
"1234"
,
"Computer"
,
department
);
department
.
addStudent
(
student2
);
department
.
removeStudent
(
student
);
Student
student3
=
new
Student
(
"reza"
,
"2132"
,
"Computer"
,
department
);
department
.
addStudent
(
student3
);
Course
course1
=
new
Course
(
"12"
,
"ap"
,
department
,
professor1
,
21
);
department
.
addCourse
(
course1
);
Course
course2
=
new
Course
(
"12"
,
"ap"
,
department2
,
professor2
,
21
);
department
.
removeCourse
(
course2
);
department
.
addProfessor
(
professor1
);
department2
.
addProfessor
(
professor1
);
}
@Test
public
void
TestAddStudent
(){
assertEquals
(
0
,
department2
.
getStudents
().
length
);
//can't add student
assertNotNull
(
department
.
getStudents
().
length
);
}
@Test
public
void
TestremoveStudents
(){
assertEquals
(
2
,
department
.
getStudents
().
length
);
}
@Test
public
void
TestGetName0
(){
assertEquals
(
"Computer"
,
department
.
getName
());
}
@Test
public
void
TestAddCourse
(){
assertNotNull
(
department
.
getCourses
().
length
);
assertEquals
(
0
,
department2
.
getCourses
().
length
);
}
@Test
public
void
TestAddProfessor
(){
assertNotNull
(
department
.
getProfessors
().
length
);
assertEquals
(
0
,
department2
.
getProfessors
().
length
);
}
}
src/test/TestProfessor.java
0 → 100644
View file @
ff41411e
package
test
;
import
com.university.*
;
import
static
junit
.
framework
.
TestCase
.
assertNotNull
;
import
static
junit
.
framework
.
TestCase
.
assertEquals
;
import
org.junit.jupiter.api.BeforeAll
;
import
org.junit.jupiter.api.Test
;
public
class
TestProfessor
{
static
Professor
professor
;
@BeforeAll
public
static
void
CreateProfessor
(){
Department
department
=
new
Department
(
"Computer"
);
professor
=
new
Professor
(
department
,
"Salmani"
);
Course
course
=
new
Course
(
"1234"
,
"AP"
,
department
,
professor
,
21
);
department
.
addCourse
(
course
);
department
.
addProfessor
(
professor
);
}
@Test
public
void
TestGetName
(){
assertEquals
(
"Salmani"
,
professor
.
getName
());
}
@Test
public
void
TestGetDepartment
(){
assertEquals
(
"Computer"
,
professor
.
getDepartment
().
getName
());
}
@Test
public
void
TestgetCourses
(){
assertNotNull
(
professor
.
getCourses
());
}
}
src/test/UniversityTest.java
0 → 100644
View file @
ff41411e
package
test
;
import
com.university.*
;
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
UniversityTest
{
static
University
university
;
@BeforeAll
public
static
void
CreateUniversity
(){
university
=
new
University
(
"AmirKabir"
);
Department
department
=
new
Department
(
"Omran"
);
Department
department1
=
new
Department
(
"Computer"
);
Department
department2
=
new
Department
(
"AeroSpace"
);
university
.
addDepartment
(
department
);
university
.
addDepartment
(
department1
);
university
.
addDepartment
(
department2
);
university
.
removeDepartment
(
department
);
}
@Test
public
void
TestaddDepartments
(){
assertNotNull
(
university
.
getDepartments
().
length
);
}
@Test
public
void
TestremoveDepartments
(){
assertEquals
(
2
,
university
.
getDepartments
().
length
);
}
@Test
public
void
TestgetName
(){
assertEquals
(
"AmirKabir"
,
university
.
getName
());
}
}
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