diff options
| author | Ron Nabuurs <nabuurs.ron@gmail.com> | 2016-05-12 09:45:23 +0200 |
|---|---|---|
| committer | Ron Nabuurs <nabuurs.ron@gmail.com> | 2016-05-12 09:45:23 +0200 |
| commit | 97be05236b7f5c8c4b7d9653604702cf9247962a (patch) | |
| tree | 0a1d1f5067fb525608a74943a2e6f81af4fbc2dc /src/main/java/org | |
| parent | bfc36e8b6e9ba119d47ad1121b8ce9d79edc9d3e (diff) | |
Fixed format, added println for cooking degrees and refactored burnt exception
Diffstat (limited to 'src/main/java/org')
| -rw-r--r-- | src/main/java/org/drtshock/BurntException.java | 12 | ||||
| -rw-r--r-- | src/main/java/org/drtshock/Potato.java | 39 | ||||
| -rw-r--r-- | src/main/java/org/drtshock/PotatoBurntException.java | 12 |
3 files changed, 32 insertions, 31 deletions
diff --git a/src/main/java/org/drtshock/BurntException.java b/src/main/java/org/drtshock/BurntException.java new file mode 100644 index 0000000..7297d39 --- /dev/null +++ b/src/main/java/org/drtshock/BurntException.java @@ -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!!"); + } + +} diff --git a/src/main/java/org/drtshock/Potato.java b/src/main/java/org/drtshock/Potato.java index 3516ee2..4eb7390 100644 --- a/src/main/java/org/drtshock/Potato.java +++ b/src/main/java/org/drtshock/Potato.java @@ -100,35 +100,36 @@ public class Potato implements Tuber { return false; } } - - /** + + /** * 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; - } + try { + return this.hasBeenBoiledInWater(); + } catch (BurntException 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 + * @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){ - return false; - } else if(waterDegrees>130){ - throw new PotatoBurntException(waterDegrees); - } - return true; - } + 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 BurntException(waterDegrees); + } + return true; + } /** * Checks if this potato is delicious. Returns the result of {@link #isBaked()}. diff --git a/src/main/java/org/drtshock/PotatoBurntException.java b/src/main/java/org/drtshock/PotatoBurntException.java deleted file mode 100644 index 518aa21..0000000 --- a/src/main/java/org/drtshock/PotatoBurntException.java +++ /dev/null @@ -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!!"); - } - -} |
