Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
agile-java
/
AgileJavaAndroid
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d478a696
authored
May 31, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lesson 6 done
parent
fb332f27
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
224 additions
and
163 deletions
app/src/main/java/com/example/paktalin/agilejava/CourseSession.java
app/src/main/java/com/example/paktalin/agilejava/Session.java
app/src/main/java/com/example/paktalin/agilejava/summer/SummerCourseSession.java
app/src/test/java/com/example/paktalin/agilejava/AllTests.java
app/src/test/java/com/example/paktalin/agilejava/CourseSessionTest.java
app/src/test/java/com/example/paktalin/agilejava/SessionTest.java
app/src/test/java/com/example/paktalin/agilejava/SummerCourseSessionTest.java
app/src/test/java/com/example/paktalin/agilejava/summer/SummerCourseSessionTest.java
app/src/main/java/com/example/paktalin/agilejava/CourseSession.java
View file @
d478a696
package
com
.
example
.
paktalin
.
agilejava
;
import
android.support.annotation.NonNull
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.GregorianCalendar
;
import
java.util.List
;
/**
* Created by Paktalin on 16/05/2018.
*/
public
class
CourseSession
implements
Comparable
<
CourseSession
>{
private
String
department
;
private
String
number
;
private
List
<
Student
>
students
=
new
ArrayList
<>();
private
Date
startDate
;
public
class
CourseSession
extends
Session
{
private
static
int
count
=
0
;
private
int
numberOfCredits
;
protected
CourseSession
(
String
department
,
String
number
,
Date
startDate
)
{
this
.
department
=
department
;
this
.
number
=
number
;
this
.
startDate
=
startDate
;
private
CourseSession
(
String
department
,
String
number
,
Date
startDate
)
{
super
(
department
,
number
,
startDate
);
}
static
CourseSession
create
(
String
department
,
String
number
,
Date
startDate
)
{
static
CourseSession
create
(
String
department
,
String
number
,
Date
startDate
)
{
incrementCount
();
return
new
CourseSession
(
department
,
number
,
startDate
);
}
String
getDepartment
()
{
return
department
;
}
String
getNumber
()
{
return
number
;
}
void
enroll
(
Student
student
)
{
students
.
add
(
student
);
student
.
addCredits
(
numberOfCredits
);
}
Student
get
(
int
index
)
{
return
students
.
get
(
index
);
}
int
getNumberOfStudents
()
{
return
students
.
size
();
}
public
Date
getEndDate
()
{
GregorianCalendar
calendar
=
new
GregorianCalendar
();
calendar
.
setTime
(
getStartDate
());
calendar
.
add
(
Calendar
.
DAY_OF_YEAR
,
getNumberOfDaysInSession
());
return
calendar
.
getTime
();
}
protected
Date
getStartDate
()
{
return
startDate
;
}
protected
int
getSessionLength
()
{
return
16
;
}
protected
int
getNumberOfDaysInSession
()
{
final
int
daysInWeek
=
7
;
final
int
daysFromFridayToMonday
=
3
;
return
getSessionLength
()
*
daysInWeek
-
daysFromFridayToMonday
;
}
List
<
Student
>
getAllStudents
()
{
return
students
;
}
static
int
getCount
()
{
return
count
;
return
CourseSession
.
count
;
}
static
void
resetCount
()
{
...
...
@@ -88,18 +27,11 @@ public class CourseSession implements Comparable<CourseSession>{
}
private
static
void
incrementCount
()
{
count
++;
}
void
setNumberOfCredits
(
int
numberOfCredits
)
{
this
.
numberOfCredits
=
numberOfCredits
;
CourseSession
.
count
++;
}
@Override
public
int
compareTo
(
@NonNull
CourseSession
that
)
{
int
compare
=
this
.
getDepartment
().
compareTo
(
that
.
getDepartment
());
if
(
compare
!=
0
)
return
compare
;
return
this
.
getNumber
().
compareTo
(
that
.
getNumber
());
protected
int
getSessionLength
()
{
return
16
;
}
}
app/src/main/java/com/example/paktalin/agilejava/Session.java
0 → 100644
View file @
d478a696
package
com
.
example
.
paktalin
.
agilejava
;
import
android.support.annotation.NonNull
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.GregorianCalendar
;
import
java.util.List
;
/**
* Created by Paktalin on 30/05/2018.
*/
public
abstract
class
Session
implements
Comparable
<
Session
>{
private
String
department
;
private
String
number
;
private
List
<
Student
>
students
=
new
ArrayList
<>();
private
Date
startDate
;
private
static
int
count
=
0
;
private
int
numberOfCredits
;
protected
Session
(
String
department
,
String
number
,
Date
startDate
)
{
this
.
department
=
department
;
this
.
number
=
number
;
this
.
startDate
=
startDate
;
}
@Override
public
int
compareTo
(
@NonNull
Session
that
)
{
int
compare
=
this
.
getDepartment
().
compareTo
(
that
.
getDepartment
());
if
(
compare
!=
0
)
return
compare
;
return
this
.
getNumber
().
compareTo
(
that
.
getNumber
());
}
protected
void
setNumberOfCredits
(
int
numberOfCredits
)
{
this
.
numberOfCredits
=
numberOfCredits
;
}
public
void
enroll
(
Student
student
)
{
students
.
add
(
student
);
student
.
addCredits
(
numberOfCredits
);
}
public
Date
getEndDate
()
{
GregorianCalendar
calendar
=
new
GregorianCalendar
();
calendar
.
setTime
(
getStartDate
());
calendar
.
add
(
Calendar
.
DAY_OF_YEAR
,
getNumberOfDaysInSession
());
return
calendar
.
getTime
();
}
private
int
getNumberOfDaysInSession
()
{
final
int
daysInWeek
=
7
;
final
int
daysFromFridayToMonday
=
3
;
return
getSessionLength
()
*
daysInWeek
-
daysFromFridayToMonday
;
}
public
List
<
Student
>
getAllStudents
()
{
return
students
;
}
protected
abstract
int
getSessionLength
();
Date
getStartDate
()
{
return
startDate
;
}
int
getNumberOfStudents
()
{
return
students
.
size
();
}
public
String
getDepartment
()
{
return
department
;
}
public
String
getNumber
()
{
return
number
;
}
Student
get
(
int
index
)
{
return
students
.
get
(
index
);
}
}
app/src/main/java/com/example/paktalin/agilejava/summer/SummerCourseSession.java
View file @
d478a696
package
com
.
example
.
paktalin
.
agilejava
.
summer
;
import
com.example.paktalin.agilejava.
Course
Session
;
import
com.example.paktalin.agilejava.Session
;
import
java.util.Date
;
...
...
@@ -8,14 +8,28 @@ import java.util.Date;
* Created by Paktalin on 28/05/2018.
*/
public
class
SummerCourseSession
extends
CourseSession
{
public
class
SummerCourseSession
extends
Session
{
private
static
int
count
=
0
;
static
SummerCourseSession
create
(
String
department
,
String
number
,
Date
startDate
)
{
private
SummerCourseSession
(
String
department
,
String
number
,
Date
startDate
)
{
super
(
department
,
number
,
startDate
);
}
public
static
SummerCourseSession
create
(
String
department
,
String
number
,
Date
startDate
)
{
incrementCount
();
return
new
SummerCourseSession
(
department
,
number
,
startDate
);
}
private
SummerCourseSession
(
String
department
,
String
number
,
Date
startDate
)
{
super
(
department
,
number
,
startDate
);
public
static
int
getCount
()
{
return
SummerCourseSession
.
count
;
}
public
static
void
resetCount
()
{
SummerCourseSession
.
count
=
0
;
}
private
static
void
incrementCount
()
{
SummerCourseSession
.
count
++;
}
@Override
...
...
app/src/test/java/com/example/paktalin/agilejava/AllTests.java
View file @
d478a696
...
...
@@ -2,6 +2,7 @@ package com.example.paktalin.agilejava;
import
com.example.paktalin.agilejava.language_tests.LanguageTests
;
import
com.example.paktalin.agilejava.language_tests.SuperClassTest
;
import
com.example.paktalin.agilejava.summer.SummerCourseSession
;
import
junit.framework.TestSuite
;
...
...
@@ -13,15 +14,19 @@ public class AllTests extends TestSuite {
public
static
TestSuite
suite
()
{
TestSuite
suite
=
new
TestSuite
();
suite
.
addTestSuite
(
StudentTest
.
class
);
suite
.
addTestSuite
(
CourseSessionTest
.
class
);
suite
.
addTestSuite
(
SummerCourseSessionTest
.
class
);
suite
.
addTestSuite
(
StudentTest
.
class
);
suite
.
addTestSuite
(
RosterReporterTest
.
class
);
suite
.
addTestSuite
(
DateUtilTest
.
class
);
suite
.
addTestSuite
(
CourseReportTest
.
class
);
suite
.
addTestSuite
(
LanguageTests
.
class
);
suite
.
addTestSuite
(
ReportCardTest
.
class
);
suite
.
addTestSuite
(
BasicGradingStrategyTest
.
class
);
suite
.
addTestSuite
(
HonorsGradingStrategyTest
.
class
);
suite
.
addTestSuite
(
LanguageTests
.
class
);
suite
.
addTestSuite
(
SuperClassTest
.
class
);
return
suite
;
}
...
...
app/src/test/java/com/example/paktalin/agilejava/CourseSessionTest.java
View file @
d478a696
package
com
.
example
.
paktalin
.
agilejava
;
import
junit.framework.TestCase
;
import
java.util.Date
;
/**
* Created by Paktalin on 16/05/2018.
*/
public
class
CourseSessionTest
extends
TestCase
{
private
CourseSession
session
;
private
Date
startDate
;
private
static
final
int
CREDITS
=
3
;
public
void
setUp
()
{
startDate
=
DateUtil
.
createDate
(
2003
,
1
,
6
);
session
=
createCourseSession
();
}
public
void
testCreate
()
{
assertEquals
(
"ENGL"
,
session
.
getDepartment
());
assertEquals
(
"101"
,
session
.
getNumber
());
assertEquals
(
0
,
session
.
getNumberOfStudents
());
assertEquals
(
startDate
,
session
.
getStartDate
());
}
public
void
testEnrollStudents
()
{
Student
student1
=
new
Student
(
"Cain DiVoe"
);
session
.
enroll
(
student1
);
assertEquals
(
CREDITS
,
student1
.
getCredits
());
assertEquals
(
student1
,
session
.
get
(
0
));
assertEquals
(
1
,
session
.
getNumberOfStudents
());
public
class
CourseSessionTest
extends
SessionTest
{
Student
student2
=
new
Student
(
"Coralee DeVaughn"
);
session
.
enroll
(
student2
);
assertEquals
(
CREDITS
,
student1
.
getCredits
());
assertEquals
(
student2
,
session
.
get
(
1
));
assertEquals
(
2
,
session
.
getNumberOfStudents
());
}
public
void
testCourseDates
()
{
Date
sixteenWeeksOut
=
DateUtil
.
createDate
(
2003
,
4
,
25
);
assertEquals
(
sixteenWeeksOut
,
session
.
getEndDate
());
@Override
protected
CourseSession
createSession
(
String
department
,
String
number
,
Date
startDate
)
{
return
CourseSession
.
create
(
department
,
number
,
startDate
);
}
public
void
testCount
()
{
CourseSession
.
resetCount
();
create
CourseSession
(
);
create
Session
(
" "
,
""
,
new
Date
()
);
assertEquals
(
1
,
CourseSession
.
getCount
());
create
CourseSession
(
);
create
Session
(
" "
,
""
,
new
Date
()
);
assertEquals
(
2
,
CourseSession
.
getCount
());
}
private
CourseSession
createCourseSession
()
{
CourseSession
session
=
CourseSession
.
create
(
"ENGL"
,
"101"
,
startDate
);
session
.
setNumberOfCredits
(
CREDITS
);
return
session
;
}
public
void
testComparable
()
{
Date
date
=
new
Date
();
CourseSession
sessionA
=
CourseSession
.
create
(
"CMSC"
,
"101"
,
date
);
CourseSession
sessionB
=
CourseSession
.
create
(
"ENGL"
,
"101"
,
date
);
assertTrue
(
sessionA
.
compareTo
(
sessionB
)
<
0
);
assertTrue
(
sessionB
.
compareTo
(
sessionA
)
>
0
);
CourseSession
sessionC
=
CourseSession
.
create
(
"CMSC"
,
"101"
,
date
);
assertEquals
(
0
,
sessionA
.
compareTo
(
sessionC
));
CourseSession
sessionD
=
CourseSession
.
create
(
"CMSC"
,
"210"
,
date
);
assertTrue
(
sessionC
.
compareTo
(
sessionD
)
<
0
);
assertTrue
(
sessionD
.
compareTo
(
sessionC
)
>
0
);
@Override
protected
Date
calculateEndDate
()
{
return
DateUtil
.
createDate
(
2003
,
4
,
25
);
}
}
app/src/test/java/com/example/paktalin/agilejava/SessionTest.java
0 → 100644
View file @
d478a696
package
com
.
example
.
paktalin
.
agilejava
;
import
junit.framework.TestCase
;
import
java.util.Date
;
/**
* Created by Paktalin on 30/05/2018.
*/
abstract
public
class
SessionTest
extends
TestCase
{
private
Session
session
;
private
Date
startDate
;
private
static
final
int
CREDITS
=
3
;
@Override
public
void
setUp
()
{
startDate
=
DateUtil
.
createDate
(
2003
,
1
,
6
);
session
=
createSession
(
"ENGL"
,
"101"
,
startDate
);
session
.
setNumberOfCredits
(
CREDITS
);
}
protected
abstract
Session
createSession
(
String
department
,
String
number
,
Date
startDate
);
public
void
testCreate
()
{
assertEquals
(
"ENGL"
,
session
.
getDepartment
());
assertEquals
(
"101"
,
session
.
getNumber
());
assertEquals
(
0
,
session
.
getNumberOfStudents
());
assertEquals
(
startDate
,
session
.
getStartDate
());
}
public
void
testEnrollStudents
()
{
Student
student1
=
new
Student
(
"Cain DiVoe"
);
session
.
enroll
(
student1
);
assertEquals
(
CREDITS
,
student1
.
getCredits
());
assertEquals
(
student1
,
session
.
get
(
0
));
assertEquals
(
1
,
session
.
getNumberOfStudents
());
Student
student2
=
new
Student
(
"Coralee DeVaughn"
);
session
.
enroll
(
student2
);
assertEquals
(
CREDITS
,
student1
.
getCredits
());
assertEquals
(
student2
,
session
.
get
(
1
));
assertEquals
(
2
,
session
.
getNumberOfStudents
());
}
public
void
testComparable
()
{
Date
date
=
new
Date
();
Session
sessionA
=
createSession
(
"CMSC"
,
"101"
,
date
);
Session
sessionB
=
createSession
(
"ENGL"
,
"101"
,
date
);
assertTrue
(
sessionA
.
compareTo
(
sessionB
)
<
0
);
assertTrue
(
sessionB
.
compareTo
(
sessionA
)
>
0
);
Session
sessionC
=
createSession
(
"CMSC"
,
"101"
,
date
);
assertEquals
(
0
,
sessionA
.
compareTo
(
sessionC
));
Session
sessionD
=
createSession
(
"CMSC"
,
"210"
,
date
);
assertTrue
(
sessionC
.
compareTo
(
sessionD
)
<
0
);
assertTrue
(
sessionD
.
compareTo
(
sessionC
)
>
0
);
}
public
void
testCourseDates
()
{
Date
startDate
=
DateUtil
.
createDate
(
2003
,
1
,
6
);
Session
session
=
createSession
(
"ENGL"
,
"200"
,
startDate
);
assertEquals
(
calculateEndDate
(),
session
.
getEndDate
());
}
protected
abstract
Date
calculateEndDate
();
}
app/src/test/java/com/example/paktalin/agilejava/SummerCourseSessionTest.java
0 → 100644
View file @
d478a696
package
com
.
example
.
paktalin
.
agilejava
;
import
com.example.paktalin.agilejava.summer.SummerCourseSession
;
import
java.util.Date
;
/**
* Created by Paktalin on 28/05/2018.
*/
public
class
SummerCourseSessionTest
extends
SessionTest
{
@Override
protected
SummerCourseSession
createSession
(
String
department
,
String
number
,
Date
startDate
)
{
return
SummerCourseSession
.
create
(
department
,
number
,
startDate
);
}
public
void
testCount
()
{
SummerCourseSession
.
resetCount
();
createSession
(
" "
,
""
,
new
Date
());
assertEquals
(
1
,
SummerCourseSession
.
getCount
());
createSession
(
" "
,
""
,
new
Date
());
assertEquals
(
2
,
SummerCourseSession
.
getCount
());
}
@Override
protected
Date
calculateEndDate
()
{
return
DateUtil
.
createDate
(
2003
,
2
,
28
);
}
}
app/src/test/java/com/example/paktalin/agilejava/summer/SummerCourseSessionTest.java
deleted
100644 → 0
View file @
fb332f27
package
com
.
example
.
paktalin
.
agilejava
.
summer
;
import
com.example.paktalin.agilejava.CourseSession
;
import
com.example.paktalin.agilejava.DateUtil
;
import
junit.framework.TestCase
;
import
java.util.Date
;
/**
* Created by Paktalin on 28/05/2018.
*/
public
class
SummerCourseSessionTest
extends
TestCase
{
public
void
testEndDate
()
{
Date
startDate
=
DateUtil
.
createDate
(
2003
,
6
,
9
);
CourseSession
session
=
SummerCourseSession
.
create
(
"ENGL"
,
"200"
,
startDate
);
Date
eightWeeksOut
=
DateUtil
.
createDate
(
2003
,
8
,
1
);
assertEquals
(
eightWeeksOut
,
session
.
getEndDate
());
}
}
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