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
3b144884
authored
May 18, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lesson 4 is done
parent
f20ab55b
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
124 additions
and
8 deletions
app/src/main/java/com/example/paktalin/agilejava/CourseSession.java
app/src/main/java/com/example/paktalin/agilejava/DateUtil.java
app/src/main/java/com/example/paktalin/agilejava/Student.java
app/src/test/java/com/example/paktalin/agilejava/CourseSessionTest.java
app/src/test/java/com/example/paktalin/agilejava/DateUtilTest.java
app/src/test/java/com/example/paktalin/agilejava/LanguageTests.java
app/src/test/java/com/example/paktalin/agilejava/RosterReporterTest.java
app/src/test/java/com/example/paktalin/agilejava/StudentTest.java
app/src/main/java/com/example/paktalin/agilejava/CourseSession.java
View file @
3b144884
...
...
@@ -14,13 +14,23 @@ class CourseSession {
private
String
number
;
private
ArrayList
<
Student
>
students
=
new
ArrayList
<>();
private
Date
startDate
;
private
static
int
count
=
0
;
private
int
numberOfCredits
;
CourseSession
(
String
department
,
String
number
,
Date
startDate
)
{
private
CourseSession
(
String
department
,
String
number
,
Date
startDate
)
{
this
.
department
=
department
;
this
.
number
=
number
;
this
.
startDate
=
startDate
;
}
static
CourseSession
create
(
String
department
,
String
number
,
Date
startDate
)
{
incrementCount
();
return
new
CourseSession
(
department
,
number
,
startDate
);
}
String
getDepartment
()
{
return
department
;
}
...
...
@@ -31,6 +41,7 @@ class CourseSession {
void
enroll
(
Student
student
)
{
students
.
add
(
student
);
student
.
addCredits
(
numberOfCredits
);
}
Student
get
(
int
index
)
{
...
...
@@ -62,4 +73,20 @@ class CourseSession {
ArrayList
<
Student
>
getAllStudents
()
{
return
students
;
}
static
int
getCount
()
{
return
count
;
}
static
void
resetCount
()
{
CourseSession
.
count
=
0
;
}
private
static
void
incrementCount
()
{
count
++;
}
void
setNumberOfCredits
(
int
numberOfCredits
)
{
this
.
numberOfCredits
=
numberOfCredits
;
}
}
app/src/main/java/com/example/paktalin/agilejava/DateUtil.java
View file @
3b144884
...
...
@@ -10,6 +10,16 @@ import java.util.GregorianCalendar;
class
DateUtil
{
//That's how static initialization block works
static
{
long
now
=
System
.
currentTimeMillis
();
then
=
new
Date
(
now
+
86400000
);
}
private
static
Date
then
;
private
DateUtil
()
{}
static
Date
createDate
(
int
year
,
int
month
,
int
date
)
{
GregorianCalendar
calendar
=
new
GregorianCalendar
();
calendar
.
clear
();
...
...
app/src/main/java/com/example/paktalin/agilejava/Student.java
View file @
3b144884
...
...
@@ -6,12 +6,37 @@ package com.example.paktalin.agilejava;
class
Student
{
private
String
name
;
private
int
credits
;
static
final
int
CREDITS_REQUIRED_FOR_FULL_TIME
=
12
;
static
final
String
IN_STATE
=
"CO"
;
private
String
state
=
""
;
Student
(
String
name
)
{
this
.
name
=
name
;
credits
=
0
;
}
String
getName
()
{
return
name
;
}
boolean
isFullTime
()
{
return
credits
>=
Student
.
CREDITS_REQUIRED_FOR_FULL_TIME
;
}
int
getCredits
()
{
return
credits
;
}
void
addCredits
(
int
credits
)
{
this
.
credits
+=
credits
;
}
boolean
isInState
()
{
return
state
.
equals
(
Student
.
IN_STATE
);
}
void
setState
(
String
state
)
{
this
.
state
=
state
.
toUpperCase
();
}
}
app/src/test/java/com/example/paktalin/agilejava/CourseSessionTest.java
View file @
3b144884
...
...
@@ -12,10 +12,11 @@ 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
=
new
CourseSession
(
"ENGL"
,
"101"
,
startDate
);
session
=
createCourseSession
(
);
}
public
void
testCreate
()
{
...
...
@@ -28,11 +29,13 @@ public class CourseSessionTest extends TestCase {
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
());
}
...
...
@@ -41,4 +44,18 @@ public class CourseSessionTest extends TestCase {
Date
sixteenWeeksOut
=
DateUtil
.
createDate
(
2003
,
4
,
25
);
assertEquals
(
sixteenWeeksOut
,
session
.
getEndDate
());
}
public
void
testCount
()
{
CourseSession
.
resetCount
();
createCourseSession
();
assertEquals
(
1
,
CourseSession
.
getCount
());
createCourseSession
();
assertEquals
(
2
,
CourseSession
.
getCount
());
}
private
CourseSession
createCourseSession
()
{
CourseSession
session
=
CourseSession
.
create
(
"ENGL"
,
"101"
,
startDate
);
session
.
setNumberOfCredits
(
CREDITS
);
return
session
;
}
}
app/src/test/java/com/example/paktalin/agilejava/DateUtilTest.java
View file @
3b144884
...
...
@@ -13,7 +13,7 @@ import java.util.GregorianCalendar;
public
class
DateUtilTest
extends
TestCase
{
public
void
testCreateDate
()
{
Date
date
=
new
DateUtil
()
.
createDate
(
2000
,
1
,
1
);
Date
date
=
DateUtil
.
createDate
(
2000
,
1
,
1
);
Calendar
calendar
=
new
GregorianCalendar
();
calendar
.
setTime
(
date
);
assertEquals
(
2000
,
calendar
.
get
(
Calendar
.
YEAR
));
...
...
app/src/test/java/com/example/paktalin/agilejava/LanguageTests.java
View file @
3b144884
...
...
@@ -22,4 +22,14 @@ public class LanguageTests extends TestCase {
assertEquals
(
"abcd"
,
"ab"
+
"c"
+
"d"
);
}
public
void
testIncrement
()
{
int
i
=
5
;
assertEquals
(
12
,
++
i
*
2
);
assertEquals
(
6
,
i
);
i
=
5
;
assertEquals
(
10
,
i
++
*
2
);
assertEquals
(
6
,
i
);
}
}
app/src/test/java/com/example/paktalin/agilejava/RosterReporterTest.java
View file @
3b144884
package
com
.
example
.
paktalin
.
agilejava
;
import
junit.framework.TestCase
;
import
static
com
.
example
.
paktalin
.
agilejava
.
RosterReporter
.
NEW_LINE
;
/**
* Created by Paktalin on 17/05/2018.
...
...
@@ -10,7 +10,7 @@ import junit.framework.TestCase;
public
class
RosterReporterTest
extends
TestCase
{
public
void
testRosterReport
()
{
CourseSession
session
=
new
CourseSession
(
"ENGL"
,
"101"
,
CourseSession
session
=
CourseSession
.
create
(
"ENGL"
,
"101"
,
DateUtil
.
createDate
(
2003
,
1
,
6
));
session
.
enroll
(
new
Student
(
"A"
));
...
...
@@ -21,9 +21,9 @@ public class RosterReporterTest extends TestCase {
assertEquals
(
RosterReporter
.
ROSTER_REPORT_HEADER
+
"A"
+
RosterReporter
.
NEW_LINE
+
"B"
+
RosterReporter
.
NEW_LINE
+
"A"
+
NEW_LINE
+
"B"
+
NEW_LINE
+
RosterReporter
.
ROSTER_REPORT_FOOTER
+
"2"
+
RosterReporter
.
NEW_LINE
,
rosterReport
);
NEW_LINE
,
rosterReport
);
}
}
app/src/test/java/com/example/paktalin/agilejava/StudentTest.java
View file @
3b144884
...
...
@@ -18,4 +18,31 @@ public class StudentTest extends TestCase {
Student
secondStudent
=
new
Student
(
secondStudentName
);
assertEquals
(
secondStudentName
,
secondStudent
.
getName
());
}
public
void
testStudentStatus
()
{
Student
student
=
new
Student
(
"a"
);
assertEquals
(
0
,
student
.
getCredits
());
assertFalse
(
student
.
isFullTime
());
student
.
addCredits
(
3
);
assertEquals
(
3
,
student
.
getCredits
());
assertFalse
(
student
.
isFullTime
());
student
.
addCredits
(
4
);
assertEquals
(
7
,
student
.
getCredits
());
assertFalse
(
student
.
isFullTime
());
student
.
addCredits
(
5
);
assertEquals
(
Student
.
CREDITS_REQUIRED_FOR_FULL_TIME
,
student
.
getCredits
());
assertTrue
(
"Not enough credits for FullTime status"
,
student
.
isFullTime
());
}
public
void
testInState
()
{
Student
student
=
new
Student
(
"a"
);
assertFalse
(
student
.
isInState
());
student
.
setState
(
Student
.
IN_STATE
);
assertTrue
(
student
.
isInState
());
student
.
setState
(
"MD"
);
assertFalse
(
student
.
isInState
());
}
}
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