Added the possibility to boil the potato if you have no oven
This commit is contained in:
parent
23f247eaac
commit
0b18d29606
2 changed files with 42 additions and 1 deletions
|
@ -102,13 +102,42 @@ public class Potato implements Tuber {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Checks if this potato is cooked. Returns the result of {@link #hasBeenBoiledInWater()}.
|
||||||
|
*
|
||||||
|
* @return true if this potato is baked, false if otherwise
|
||||||
|
*/
|
||||||
|
public boolean isCooked() {
|
||||||
|
try{
|
||||||
|
return this.hasBeenBoiledInWater();
|
||||||
|
} catch (PotatoBurntException e){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the potato is succesfully boiled at the right amount of degrees.
|
||||||
|
*
|
||||||
|
* @return true if the potato has succesfully been boiled, false if otherwise
|
||||||
|
* @throws PotatoBurntException if the potato has been burned during the process of cooking
|
||||||
|
*/
|
||||||
|
public boolean hasBeenBoiledInWater() throws PotatoBurntException{
|
||||||
|
int waterDegrees = (int)(Math.random()*200);
|
||||||
|
if(waterDegrees<70){
|
||||||
|
return false;
|
||||||
|
} else if(waterDegrees>130){
|
||||||
|
throw new PotatoBurntException(waterDegrees);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* Checks if this potato is delicious. Returns the result of {@link #isBaked()}.
|
* Checks if this potato is delicious. Returns the result of {@link #isBaked()}.
|
||||||
*
|
*
|
||||||
* @return true if this potato is delicious, false if otherwise
|
* @return true if this potato is delicious, false if otherwise
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isDelicious() {
|
public boolean isDelicious() {
|
||||||
return this.isBaked();
|
return this.isBaked() || this.isBoiled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
12
src/main/java/org/drtshock/PotatoBurntException.java
Normal file
12
src/main/java/org/drtshock/PotatoBurntException.java
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
package org.drtshock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An exception to describe that something went wrong with our oven!
|
||||||
|
*/
|
||||||
|
public class PotatoBurntException extends Exception {
|
||||||
|
|
||||||
|
public PotatoBurntException(int degrees) {
|
||||||
|
super("Potato is badly burnt by trying to boil it at "+degrees+" degrees!!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue