aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/drtshock/BurntException.java12
-rw-r--r--src/main/java/org/drtshock/Potato.java32
2 files changed, 43 insertions, 1 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 81e02f4..4eb7390 100644
--- a/src/main/java/org/drtshock/Potato.java
+++ b/src/main/java/org/drtshock/Potato.java
@@ -102,13 +102,43 @@ 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 (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 BurntException if the potato has been burned during the process of cooking
+ */
+ 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()}.
*
* @return true if this potato is delicious, false if otherwise
*/
@Override
public boolean isDelicious() {
- return this.isBaked();
+ return this.isBaked() || this.isCooked();
}
/**