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
983b8d32
authored
May 19, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lesson 5 is done
parent
3b144884
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
223 additions
and
21 deletions
app/src/main/java/com/example/paktalin/agilejava/BasicGradingStrategy.java
app/src/main/java/com/example/paktalin/agilejava/CourseReport.java
app/src/main/java/com/example/paktalin/agilejava/CourseSession.java
app/src/main/java/com/example/paktalin/agilejava/GradingStrategy.java
app/src/main/java/com/example/paktalin/agilejava/HonorsGradingStrategy.java
app/src/main/java/com/example/paktalin/agilejava/Student.java
app/src/test/java/com/example/paktalin/agilejava/AllTests.java
app/src/test/java/com/example/paktalin/agilejava/CourseReportTest.java
app/src/test/java/com/example/paktalin/agilejava/CourseSessionTest.java
app/src/test/java/com/example/paktalin/agilejava/ExampleUnitTest.java
app/src/test/java/com/example/paktalin/agilejava/LanguageTests.java
app/src/test/java/com/example/paktalin/agilejava/StudentTest.java
app/src/main/java/com/example/paktalin/agilejava/BasicGradingStrategy.java
0 → 100644
View file @
983b8d32
package
com
.
example
.
paktalin
.
agilejava
;
/**
* Created by Paktalin on 18/05/2018.
*/
class
BasicGradingStrategy
implements
GradingStrategy
{
@Override
public
int
getGradePointsFor
(
Student
.
Grade
grade
)
{
if
(
grade
==
Student
.
Grade
.
A
)
return
4
;
if
(
grade
==
Student
.
Grade
.
B
)
return
3
;
if
(
grade
==
Student
.
Grade
.
C
)
return
2
;
if
(
grade
==
Student
.
Grade
.
D
)
return
1
;
return
0
;
}
}
app/src/main/java/com/example/paktalin/agilejava/CourseReport.java
0 → 100644
View file @
983b8d32
package
com
.
example
.
paktalin
.
agilejava
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
/**
* Created by Paktalin on 18/05/2018.
*/
class
CourseReport
{
private
List
<
CourseSession
>
sessions
=
new
ArrayList
<>();
void
add
(
CourseSession
session
)
{
sessions
.
add
(
session
);
Collections
.
sort
(
sessions
);
}
public
String
text
()
{
StringBuilder
buffer
=
new
StringBuilder
();
for
(
CourseSession
session
:
sessions
)
{
buffer
.
append
(
session
.
getDepartment
());
buffer
.
append
(
" "
);
buffer
.
append
(
session
.
getNumber
());
buffer
.
append
(
RosterReporter
.
NEW_LINE
);
}
return
buffer
.
toString
();
}
}
app/src/main/java/com/example/paktalin/agilejava/CourseSession.java
View file @
983b8d32
package
com
.
example
.
paktalin
.
agilejava
;
package
com
.
example
.
paktalin
.
agilejava
;
import
android.support.annotation.NonNull
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.GregorianCalendar
;
import
java.util.GregorianCalendar
;
import
java.util.List
;
/**
/**
* Created by Paktalin on 16/05/2018.
* Created by Paktalin on 16/05/2018.
*/
*/
class
CourseSession
{
class
CourseSession
implements
Comparable
<
CourseSession
>
{
private
String
department
;
private
String
department
;
private
String
number
;
private
String
number
;
private
Array
List
<
Student
>
students
=
new
ArrayList
<>();
private
List
<
Student
>
students
=
new
ArrayList
<>();
private
Date
startDate
;
private
Date
startDate
;
private
static
int
count
=
0
;
private
static
int
count
=
0
;
private
int
numberOfCredits
;
private
int
numberOfCredits
;
...
@@ -70,7 +73,7 @@ class CourseSession {
...
@@ -70,7 +73,7 @@ class CourseSession {
return
sessionLength
*
daysInWeek
-
daysFromFridayToMonday
;
return
sessionLength
*
daysInWeek
-
daysFromFridayToMonday
;
}
}
Array
List
<
Student
>
getAllStudents
()
{
List
<
Student
>
getAllStudents
()
{
return
students
;
return
students
;
}
}
...
@@ -89,4 +92,12 @@ class CourseSession {
...
@@ -89,4 +92,12 @@ class CourseSession {
void
setNumberOfCredits
(
int
numberOfCredits
)
{
void
setNumberOfCredits
(
int
numberOfCredits
)
{
this
.
numberOfCredits
=
numberOfCredits
;
this
.
numberOfCredits
=
numberOfCredits
;
}
}
@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
());
}
}
}
app/src/main/java/com/example/paktalin/agilejava/GradingStrategy.java
0 → 100644
View file @
983b8d32
package
com
.
example
.
paktalin
.
agilejava
;
/**
* Created by Paktalin on 18/05/2018.
*/
interface
GradingStrategy
{
int
getGradePointsFor
(
Student
.
Grade
grade
);
}
app/src/main/java/com/example/paktalin/agilejava/HonorsGradingStrategy.java
0 → 100644
View file @
983b8d32
package
com
.
example
.
paktalin
.
agilejava
;
/**
* Created by Paktalin on 18/05/2018.
*/
class
HonorsGradingStrategy
implements
GradingStrategy
{
@Override
public
int
getGradePointsFor
(
Student
.
Grade
grade
)
{
int
points
=
new
BasicGradingStrategy
().
getGradePointsFor
(
grade
);
if
(
points
!=
0
)
points
++;
return
points
;
}
}
app/src/main/java/com/example/paktalin/agilejava/Student.java
View file @
983b8d32
package
com
.
example
.
paktalin
.
agilejava
;
package
com
.
example
.
paktalin
.
agilejava
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
/**
* Created by Paktalin on 15/05/2018.
* Created by Paktalin on 15/05/2018.
*/
*/
...
@@ -10,6 +13,10 @@ class Student {
...
@@ -10,6 +13,10 @@ class Student {
static
final
int
CREDITS_REQUIRED_FOR_FULL_TIME
=
12
;
static
final
int
CREDITS_REQUIRED_FOR_FULL_TIME
=
12
;
static
final
String
IN_STATE
=
"CO"
;
static
final
String
IN_STATE
=
"CO"
;
private
String
state
=
""
;
private
String
state
=
""
;
private
List
<
Grade
>
grades
=
new
ArrayList
<>();
private
GradingStrategy
gradingStrategy
=
new
BasicGradingStrategy
();
enum
Grade
{
A
,
B
,
C
,
D
,
F
};
Student
(
String
name
)
{
Student
(
String
name
)
{
this
.
name
=
name
;
this
.
name
=
name
;
...
@@ -39,4 +46,21 @@ class Student {
...
@@ -39,4 +46,21 @@ class Student {
void
setState
(
String
state
)
{
void
setState
(
String
state
)
{
this
.
state
=
state
.
toUpperCase
();
this
.
state
=
state
.
toUpperCase
();
}
}
void
addGrade
(
Grade
grade
)
{
grades
.
add
(
grade
);
}
double
getGpa
()
{
if
(
grades
.
isEmpty
())
return
0.0
;
double
total
=
0.0
;
for
(
Grade
grade
:
grades
)
total
+=
gradingStrategy
.
getGradePointsFor
(
grade
);
return
total
/
grades
.
size
();
}
void
setGradingStrategy
(
HonorsGradingStrategy
gradingStrategy
)
{
this
.
gradingStrategy
=
gradingStrategy
;
}
}
}
app/src/test/java/com/example/paktalin/agilejava/AllTests.java
View file @
983b8d32
...
@@ -14,6 +14,7 @@ public class AllTests extends TestSuite {
...
@@ -14,6 +14,7 @@ public class AllTests extends TestSuite {
suite
.
addTestSuite
(
CourseSessionTest
.
class
);
suite
.
addTestSuite
(
CourseSessionTest
.
class
);
suite
.
addTestSuite
(
RosterReporterTest
.
class
);
suite
.
addTestSuite
(
RosterReporterTest
.
class
);
suite
.
addTestSuite
(
DateUtilTest
.
class
);
suite
.
addTestSuite
(
DateUtilTest
.
class
);
suite
.
addTestSuite
(
CourseReportTest
.
class
);
return
suite
;
return
suite
;
}
}
}
}
app/src/test/java/com/example/paktalin/agilejava/CourseReportTest.java
0 → 100644
View file @
983b8d32
package
com
.
example
.
paktalin
.
agilejava
;
import
junit.framework.TestCase
;
import
java.util.Date
;
import
static
com
.
example
.
paktalin
.
agilejava
.
RosterReporter
.
NEW_LINE
;
/**
* Created by Paktalin on 18/05/2018.
*/
public
class
CourseReportTest
extends
TestCase
{
public
void
testReport
()
{
final
Date
date
=
new
Date
();
CourseReport
report
=
new
CourseReport
();
report
.
add
(
CourseSession
.
create
(
"ENGL"
,
"101"
,
date
));
report
.
add
(
CourseSession
.
create
(
"CZEC"
,
"200"
,
date
));
report
.
add
(
CourseSession
.
create
(
"ITAL"
,
"410"
,
date
));
report
.
add
(
CourseSession
.
create
(
"CZEC"
,
"220"
,
date
));
report
.
add
(
CourseSession
.
create
(
"ITAL"
,
"330"
,
date
));
assertEquals
(
"CZEC 200"
+
NEW_LINE
+
"CZEC 220"
+
NEW_LINE
+
"ENGL 101"
+
NEW_LINE
+
"ITAL 330"
+
NEW_LINE
+
"ITAL 410"
+
NEW_LINE
,
report
.
text
());
}
}
app/src/test/java/com/example/paktalin/agilejava/CourseSessionTest.java
View file @
983b8d32
...
@@ -58,4 +58,19 @@ public class CourseSessionTest extends TestCase {
...
@@ -58,4 +58,19 @@ public class CourseSessionTest extends TestCase {
session
.
setNumberOfCredits
(
CREDITS
);
session
.
setNumberOfCredits
(
CREDITS
);
return
session
;
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
);
}
}
}
app/src/test/java/com/example/paktalin/agilejava/ExampleUnitTest.java
deleted
100644 → 0
View file @
3b144884
package
com
.
example
.
paktalin
.
agilejava
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public
class
ExampleUnitTest
{
@Test
public
void
addition_isCorrect
()
throws
Exception
{
assertEquals
(
4
,
2
+
2
);
}
}
\ No newline at end of file
app/src/test/java/com/example/paktalin/agilejava/LanguageTests.java
View file @
983b8d32
...
@@ -2,6 +2,9 @@ package com.example.paktalin.agilejava;
...
@@ -2,6 +2,9 @@ package com.example.paktalin.agilejava;
import
junit.framework.TestCase
;
import
junit.framework.TestCase
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
/**
* Created by Paktalin on 17/05/2018.
* Created by Paktalin on 17/05/2018.
*/
*/
...
@@ -32,4 +35,24 @@ public class LanguageTests extends TestCase {
...
@@ -32,4 +35,24 @@ public class LanguageTests extends TestCase {
assertEquals
(
6
,
i
);
assertEquals
(
6
,
i
);
}
}
public
void
testCollectionsSort
()
{
List
<
String
>
list
=
new
ArrayList
<>();
list
.
add
(
"Heller"
);
list
.
add
(
"Kafka"
);
list
.
add
(
"Camus"
);
list
.
add
(
"Boyle"
);
java
.
util
.
Collections
.
sort
(
list
);
assertEquals
(
"Boyle"
,
list
.
get
(
0
));
assertEquals
(
"Camus"
,
list
.
get
(
1
));
assertEquals
(
"Heller"
,
list
.
get
(
2
));
assertEquals
(
"Kafka"
,
list
.
get
(
3
));
}
public
void
testCompareTo
()
{
assertTrue
(
"A"
.
compareTo
(
"B"
)
<
0
);
assertEquals
(
0
,
"A"
.
compareTo
(
"A"
));
assertTrue
(
"B"
.
compareTo
(
"A"
)
>
0
);
}
}
}
app/src/test/java/com/example/paktalin/agilejava/StudentTest.java
View file @
983b8d32
...
@@ -45,4 +45,47 @@ public class StudentTest extends TestCase {
...
@@ -45,4 +45,47 @@ public class StudentTest extends TestCase {
student
.
setState
(
"MD"
);
student
.
setState
(
"MD"
);
assertFalse
(
student
.
isInState
());
assertFalse
(
student
.
isInState
());
}
}
public
void
testCalculateGpa
()
{
Student
student
=
new
Student
(
"a"
);
assertGpa
(
student
,
0.0
);
student
.
addGrade
(
Student
.
Grade
.
A
);
assertGpa
(
student
,
4.0
);
student
.
addGrade
(
Student
.
Grade
.
B
);
assertGpa
(
student
,
3.5
);
student
.
addGrade
(
Student
.
Grade
.
C
);
assertGpa
(
student
,
3.0
);
student
.
addGrade
(
Student
.
Grade
.
D
);
assertGpa
(
student
,
2.5
);
student
.
addGrade
(
Student
.
Grade
.
F
);
assertGpa
(
student
,
2.0
);
}
public
void
testCalculateHonorsStudentGpa
()
{
Student
student
=
createHonorsStudent
();
assertGpa
(
student
,
0.0
);
student
.
addGrade
(
Student
.
Grade
.
A
);
assertGpa
(
student
,
5.0
);
student
.
addGrade
(
Student
.
Grade
.
B
);
assertGpa
(
student
,
4.5
);
student
.
addGrade
(
Student
.
Grade
.
C
);
assertGpa
(
student
,
4.0
);
student
.
addGrade
(
Student
.
Grade
.
D
);
assertGpa
(
student
,
3.5
);
student
.
addGrade
(
Student
.
Grade
.
F
);
assertGpa
(
student
,
2.8
);
}
private
void
assertGpa
(
Student
student
,
double
expectedGpa
)
{
final
double
GRADE_TOLERANCE
=
0.05
;
assertEquals
(
expectedGpa
,
student
.
getGpa
(),
GRADE_TOLERANCE
);
}
private
Student
createHonorsStudent
()
{
Student
student
=
new
Student
(
"a"
);
student
.
setGradingStrategy
(
new
HonorsGradingStrategy
());
return
student
;
}
}
}
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