Merge pull request #1 from ronneke1996/master
Fixed format, added println for cooking degrees and refactored burnt …
This commit is contained in:
commit
c53eaed760
3 changed files with 32 additions and 31 deletions
12
src/main/java/org/drtshock/BurntException.java
Normal file
12
src/main/java/org/drtshock/BurntException.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
package org.drtshock;
|
||||
|
||||
/**
|
||||
* An exception to describe that something went wrong with our oven!
|
||||
*/
|
||||
public class BurntException extends Exception {
|
||||
|
||||
public BurntException(int degrees) {
|
||||
super("Potato is badly burnt by trying to boil it at " + degrees + " degrees!!");
|
||||
}
|
||||
|
||||
}
|
|
@ -107,9 +107,9 @@ public class Potato implements Tuber {
|
|||
* @return true if this potato is baked, false if otherwise
|
||||
*/
|
||||
public boolean isCooked() {
|
||||
try{
|
||||
try {
|
||||
return this.hasBeenBoiledInWater();
|
||||
} catch (PotatoBurntException e){
|
||||
} catch (BurntException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -118,14 +118,15 @@ public class Potato implements Tuber {
|
|||
* 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
|
||||
* @throws BurntException 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){
|
||||
public boolean hasBeenBoiledInWater() throws BurntException {
|
||||
int waterDegrees = (int) (Math.random() * 200);
|
||||
System.out.println("Trying to boil potato at " + waterDegrees + " degrees.");
|
||||
if (waterDegrees < 70) {
|
||||
return false;
|
||||
} else if(waterDegrees>130){
|
||||
throw new PotatoBurntException(waterDegrees);
|
||||
} else if (waterDegrees > 130) {
|
||||
throw new BurntException(waterDegrees);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
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