I have been given following problem to solve:
- If the integer is divisible by 3, return the string "Java".
- If the integer is divisible by 3 and divisible by 4, return the string "Coffee"
- If the integer is one of the above and is even, add "Script" to the end of the string. Otherwise, return the string "mocha_missing!"
Sample Input and Output
- caffeineBuzz(1) => "mocha_missing"
- caffeineBuzz(3) => "Java"
- caffeineBuzz(6) => "JavaScript"
- caffeineBuzz(12) => "CoffeeScript"
//Class
public class CoffieScriptGenerator {
public String caffeineBuzzz(Integer number) {
if(isDivisbleByThreeAndFour(number))
{
if(isEven(number))
return "CoffeeScript";
else
return "Coffee";
}
if(isDivisbleByThree(number))
{
if(isEven(number))
return "JavaScript";
else
return "Java";
}
return "mocha_missing!";
}
private boolean isEven(Integer number) {
return number%2==0;
}
private boolean isDivisbleByThreeAndFour(Integer number) {
return isDivisbleByThree(number) && number%4==0;
}
private boolean isDivisbleByThree(Integer number) {
return number%3==0;
}
}
Please provide suggestions to refactor it and improve it and how i can improve such nesting if else with help of patterns like strategy.
int
, notInteger
\$\endgroup\$