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
b1321304
authored
May 28, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Grading strategy refactoring in Lesson 6
parent
635ac868
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
57 additions
and
22 deletions
app/src/main/java/com/example/paktalin/agilejava/BasicGradingStrategy.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/BasicGradingStrategyTest.java
app/src/test/java/com/example/paktalin/agilejava/HonorsGradingStrategyTest.java
app/src/main/java/com/example/paktalin/agilejava/BasicGradingStrategy.java
View file @
b1321304
...
...
@@ -4,15 +4,9 @@ package com.example.paktalin.agilejava;
* Created by Paktalin on 18/05/2018.
*/
class
BasicGradingStrategy
implements
GradingStrategy
{
@Override
class
BasicGradingStrategy
{
public
int
getGradePointsFor
(
Student
.
Grade
grade
)
{
switch
(
grade
)
{
case
A:
return
4
;
case
B:
return
3
;
case
C:
return
2
;
case
D:
return
1
;
default
:
return
0
;
}
return
grade
.
getPoints
();
}
}
app/src/main/java/com/example/paktalin/agilejava/GradingStrategy.java
deleted
100644 → 0
View file @
635ac868
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
View file @
b1321304
...
...
@@ -4,10 +4,11 @@ package com.example.paktalin.agilejava;
* Created by Paktalin on 18/05/2018.
*/
class
HonorsGradingStrategy
implements
GradingStrategy
{
class
HonorsGradingStrategy
extends
BasicGradingStrategy
{
@Override
public
int
getGradePointsFor
(
Student
.
Grade
grade
)
{
int
points
=
new
BasicGradingStrategy
()
.
getGradePointsFor
(
grade
);
int
points
=
super
.
getGradePointsFor
(
grade
);
if
(
points
!=
0
)
points
++;
return
points
;
...
...
app/src/main/java/com/example/paktalin/agilejava/Student.java
View file @
b1321304
...
...
@@ -14,9 +14,18 @@ class Student {
static
final
String
IN_STATE
=
"CO"
;
private
String
state
=
""
;
private
List
<
Grade
>
grades
=
new
ArrayList
<>();
private
GradingStrategy
gradingStrategy
=
new
BasicGradingStrategy
();
private
Basic
GradingStrategy
gradingStrategy
=
new
BasicGradingStrategy
();
enum
Grade
{
A
,
B
,
C
,
D
,
F
};
enum
Grade
{
A
(
4
),
B
(
3
),
C
(
2
),
D
(
1
),
F
(
0
);
private
int
points
;
Grade
(
int
points
)
{
this
.
points
=
points
;
}
int
getPoints
()
{
return
points
;
}
}
Student
(
String
name
)
{
this
.
name
=
name
;
...
...
app/src/test/java/com/example/paktalin/agilejava/AllTests.java
View file @
b1321304
...
...
@@ -17,6 +17,8 @@ public class AllTests extends TestSuite {
suite
.
addTestSuite
(
CourseReportTest
.
class
);
suite
.
addTestSuite
(
LanguageTests
.
class
);
suite
.
addTestSuite
(
ReportCardTest
.
class
);
suite
.
addTestSuite
(
BasicGradingStrategyTest
.
class
);
suite
.
addTestSuite
(
HonorsGradingStrategyTest
.
class
);
return
suite
;
}
}
app/src/test/java/com/example/paktalin/agilejava/BasicGradingStrategyTest.java
0 → 100644
View file @
b1321304
package
com
.
example
.
paktalin
.
agilejava
;
import
junit.framework.TestCase
;
/**
* Created by Paktalin on 28/05/2018.
*/
public
class
BasicGradingStrategyTest
extends
TestCase
{
public
void
testGetGradePoints
()
{
BasicGradingStrategy
strategy
=
new
BasicGradingStrategy
();
assertEquals
(
4
,
strategy
.
getGradePointsFor
(
Student
.
Grade
.
A
));
assertEquals
(
3
,
strategy
.
getGradePointsFor
(
Student
.
Grade
.
B
));
assertEquals
(
2
,
strategy
.
getGradePointsFor
(
Student
.
Grade
.
C
));
assertEquals
(
1
,
strategy
.
getGradePointsFor
(
Student
.
Grade
.
D
));
assertEquals
(
0
,
strategy
.
getGradePointsFor
(
Student
.
Grade
.
F
));
}
}
app/src/test/java/com/example/paktalin/agilejava/HonorsGradingStrategyTest.java
0 → 100644
View file @
b1321304
package
com
.
example
.
paktalin
.
agilejava
;
import
junit.framework.TestCase
;
/**
* Created by Paktalin on 28/05/2018.
*/
public
class
HonorsGradingStrategyTest
extends
TestCase
{
public
void
testGetGradePoints
()
{
HonorsGradingStrategy
strategy
=
new
HonorsGradingStrategy
();
assertEquals
(
5
,
strategy
.
getGradePointsFor
(
Student
.
Grade
.
A
));
assertEquals
(
4
,
strategy
.
getGradePointsFor
(
Student
.
Grade
.
B
));
assertEquals
(
3
,
strategy
.
getGradePointsFor
(
Student
.
Grade
.
C
));
assertEquals
(
2
,
strategy
.
getGradePointsFor
(
Student
.
Grade
.
D
));
assertEquals
(
0
,
strategy
.
getGradePointsFor
(
Student
.
Grade
.
F
));
}
}
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