From 0b18d29606c8375bc5159121d858f6692f4e455f Mon Sep 17 00:00:00 2001 From: Simon Baars Date: Wed, 11 May 2016 16:08:00 +0200 Subject: [PATCH 1/3] Added the possibility to boil the potato if you have no oven --- src/main/java/org/drtshock/Potato.java | 31 ++++++++++++++++++- .../org/drtshock/PotatoBurntException.java | 12 +++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/drtshock/PotatoBurntException.java diff --git a/src/main/java/org/drtshock/Potato.java b/src/main/java/org/drtshock/Potato.java index 81e02f4..6fcd26f 100644 --- a/src/main/java/org/drtshock/Potato.java +++ b/src/main/java/org/drtshock/Potato.java @@ -100,6 +100,35 @@ 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; + } + } + + /** + * 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()}. @@ -108,7 +137,7 @@ public class Potato implements Tuber { */ @Override public boolean isDelicious() { - return this.isBaked(); + return this.isBaked() || this.isBoiled(); } /** diff --git a/src/main/java/org/drtshock/PotatoBurntException.java b/src/main/java/org/drtshock/PotatoBurntException.java new file mode 100644 index 0000000..518aa21 --- /dev/null +++ b/src/main/java/org/drtshock/PotatoBurntException.java @@ -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!!"); + } + +} From bfc36e8b6e9ba119d47ad1121b8ce9d79edc9d3e Mon Sep 17 00:00:00 2001 From: Simon Baars Date: Wed, 11 May 2016 16:11:08 +0200 Subject: [PATCH 2/3] Fixed an issue with my previous commit --- src/main/java/org/drtshock/Potato.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/drtshock/Potato.java b/src/main/java/org/drtshock/Potato.java index 6fcd26f..3516ee2 100644 --- a/src/main/java/org/drtshock/Potato.java +++ b/src/main/java/org/drtshock/Potato.java @@ -137,7 +137,7 @@ public class Potato implements Tuber { */ @Override public boolean isDelicious() { - return this.isBaked() || this.isBoiled(); + return this.isBaked() || this.isCooked(); } /** From 97be05236b7f5c8c4b7d9653604702cf9247962a Mon Sep 17 00:00:00 2001 From: Ron Nabuurs Date: Thu, 12 May 2016 09:45:23 +0200 Subject: [PATCH 3/3] Fixed format, added println for cooking degrees and refactored burnt exception --- .../java/org/drtshock/BurntException.java | 12 ++++++ src/main/java/org/drtshock/Potato.java | 39 ++++++++++--------- .../org/drtshock/PotatoBurntException.java | 12 ------ 3 files changed, 32 insertions(+), 31 deletions(-) create mode 100644 src/main/java/org/drtshock/BurntException.java delete mode 100644 src/main/java/org/drtshock/PotatoBurntException.java 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!!"); - } - -}