Commit 635ac868 by Paktalin

Lesson 6 in progress

parent 983b8d32
...@@ -7,10 +7,12 @@ package com.example.paktalin.agilejava; ...@@ -7,10 +7,12 @@ package com.example.paktalin.agilejava;
class BasicGradingStrategy implements GradingStrategy { class BasicGradingStrategy implements GradingStrategy {
@Override @Override
public int getGradePointsFor(Student.Grade grade) { public int getGradePointsFor(Student.Grade grade) {
if(grade == Student.Grade.A) return 4; switch(grade) {
if(grade == Student.Grade.B) return 3; case A: return 4;
if(grade == Student.Grade.C) return 2; case B: return 3;
if(grade == Student.Grade.D) return 1; case C: return 2;
return 0; case D: return 1;
default: return 0;
}
} }
} }
package com.example.paktalin.agilejava;
import java.util.EnumMap;
import java.util.Map;
/**
* Created by Paktalin on 27/05/2018.
*/
class ReportCard {
static final String A_MESSAGE = "Excellent!";
static final String B_MESSAGE = "Very good";
static final String C_MESSAGE = "Hmmm...";
static final String D_MESSAGE = "You're not trying";
static final String F_MESSAGE = "Loser";
private Map<Student.Grade, String> messages = null;
public String getMessage(Student.Grade grade) {
return getMessages().get(grade);
}
private Map<Student.Grade, String> getMessages() {
if (messages == null)
loadMessages();
return messages;
}
private void loadMessages() {
messages = new EnumMap<>(Student.Grade.class);
messages.put(Student.Grade.A, A_MESSAGE);
messages.put(Student.Grade.B, B_MESSAGE);
messages.put(Student.Grade.C, C_MESSAGE);
messages.put(Student.Grade.D, D_MESSAGE);
messages.put(Student.Grade.F, F_MESSAGE);
}
}
...@@ -15,6 +15,8 @@ public class AllTests extends TestSuite { ...@@ -15,6 +15,8 @@ public class AllTests extends TestSuite {
suite.addTestSuite(RosterReporterTest.class); suite.addTestSuite(RosterReporterTest.class);
suite.addTestSuite(DateUtilTest.class); suite.addTestSuite(DateUtilTest.class);
suite.addTestSuite(CourseReportTest.class); suite.addTestSuite(CourseReportTest.class);
suite.addTestSuite(LanguageTests.class);
suite.addTestSuite(ReportCardTest.class);
return suite; return suite;
} }
} }
...@@ -55,4 +55,30 @@ public class LanguageTests extends TestCase { ...@@ -55,4 +55,30 @@ public class LanguageTests extends TestCase {
assertTrue("B".compareTo("A") > 0); assertTrue("B".compareTo("A") > 0);
} }
enum Score {fieldGoal, touchdown, extraPoint, twoPointConversion, safety}
public void testSwitchResults() {
int totalPoints = 0;
Score score = Score.touchdown;
switch (score) {
case fieldGoal:
totalPoints += 3;
break;
case touchdown:
totalPoints += 6;
break;
case extraPoint:
totalPoints += 1;
break;
case twoPointConversion:
case safety:
totalPoints += 2;
break;
}
assertEquals(6, totalPoints);
}
} }
package com.example.paktalin.agilejava;
import junit.framework.TestCase;
/**
* Created by Paktalin on 27/05/2018.
*/
public class ReportCardTest extends TestCase {
public void testMessage() {
ReportCard card = new ReportCard();
assertEquals(ReportCard.A_MESSAGE, card.getMessage(Student.Grade.A));
assertEquals(ReportCard.B_MESSAGE, card.getMessage(Student.Grade.B));
assertEquals(ReportCard.C_MESSAGE, card.getMessage(Student.Grade.C));
assertEquals(ReportCard.D_MESSAGE, card.getMessage(Student.Grade.D));
assertEquals(ReportCard.F_MESSAGE, card.getMessage(Student.Grade.F));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment