This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int score() { | |
int score = 0; | |
int frameIndex = 0; | |
for (int frame = 0; frame < 10; frame++) { | |
if (isStrike(frameIndex)) { | |
score += 10 + rolls[frameIndex+1] + rolls[frameIndex+2]; | |
frameIndex++; | |
} else if (isSpare(frameIndex)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum FrameType { | |
STRIKE, | |
SPARE, | |
OPEN; | |
public static FrameType classifyFrame(int firstRoll, int secondRoll) { | |
if (firstRoll == MAX_PINS) { | |
return STRIKE; | |
} | |
if (firstRoll + secondRoll == MAX_PINS) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum FrameType { | |
STRIKE { | |
public int scoreFrame(int rolls[], int frameIndex) { | |
return MAX_PINS + rolls[frameIndex+1] + rolls[frameIndex+2]; | |
} | |
}, | |
SPARE {...}, | |
OPEN {...}; | |
public static FrameType classifyFrame(int firstRoll, int secondRoll) {...} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BowlingGame { | |
public static final int MAX_PINS = 10; | |
public enum FrameType { | |
STRIKE { | |
public int scoreFrame(int rolls[], int frameIndex) { | |
return MAX_PINS + rolls[frameIndex+1] + rolls[frameIndex+2]; | |
} | |
public int rollsInFrame() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum FrameType { | |
STRIKE { | |
public int scoreFrame(int rolls[], int frameIndex) { | |
return MAX_PINS + rolls[frameIndex+1] + rolls[frameIndex+2]; | |
} | |
public int rollsInFrame() { | |
return 1; | |
} | |
}, | |
SPARE { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum FrameType { | |
STRIKE((rolls, frameIndex) -> MAX_PINS + rolls[frameIndex+1] + rolls[frameIndex+2], | |
1), | |
SPARE((rolls, frameIndex) -> MAX_PINS + rolls[frameIndex+2], | |
2), | |
OPEN((rolls, frameIndex) -> rolls[frameIndex] + rolls[frameIndex+1], | |
2); | |
private BiFunction<int[], Integer, Integer> scoreFunction; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UnknownJobRole extends JobRole { | |
@Override | |
public boolean isUnderSalaryBand() { | |
return false; | |
} | |
@Override | |
public boolean isHighTurnOverRole() { | |
return false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum VendorType { | |
MANUFACTURER, | |
DISTRIBUTOR, | |
UNKNOWN; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Employee { | |
JobRole jobRole; | |
public boolean isRaiseDue() { | |
return jobRole.isUnderSalaryBand() || | |
jobRole.isHighTurnOverRole(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void validateCity(String cityCode) { | |
Optional<City> city = findCity(cityCode); | |
if (city.isPresent()) { | |
return; | |
} | |
setError(CITY_INVALID, cityCode); | |
} | |
public Optional<City> findCity(String cityCode) { | |
City city = cityRepository.get(cityCode); |
OlderNewer