aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/drtshock/BurntException.java4
-rw-r--r--src/main/java/org/drtshock/NotDeliciousReason.java1
-rw-r--r--src/main/java/org/drtshock/Potato.java21
3 files changed, 12 insertions, 14 deletions
diff --git a/src/main/java/org/drtshock/BurntException.java b/src/main/java/org/drtshock/BurntException.java
index 7297d39..e76b7f9 100644
--- a/src/main/java/org/drtshock/BurntException.java
+++ b/src/main/java/org/drtshock/BurntException.java
@@ -9,4 +9,8 @@ public class BurntException extends Exception {
super("Potato is badly burnt by trying to boil it at " + degrees + " degrees!!");
}
+ public BurntException() {
+ super("Potato is badly burnt by baking for too long!");
+ }
+
}
diff --git a/src/main/java/org/drtshock/NotDeliciousReason.java b/src/main/java/org/drtshock/NotDeliciousReason.java
index d093f08..1be8deb 100644
--- a/src/main/java/org/drtshock/NotDeliciousReason.java
+++ b/src/main/java/org/drtshock/NotDeliciousReason.java
@@ -6,7 +6,6 @@ package org.drtshock;
public enum NotDeliciousReason {
UNDERCOOKED,
- OVERCOOKED,
NOT_DELICIOUS_CONDIMENT,
EXPIRED_CONDIMENT
diff --git a/src/main/java/org/drtshock/Potato.java b/src/main/java/org/drtshock/Potato.java
index 25205f7..abb0305 100644
--- a/src/main/java/org/drtshock/Potato.java
+++ b/src/main/java/org/drtshock/Potato.java
@@ -77,14 +77,17 @@ public class Potato implements Tuber {
* @return true if potato is in the oven, false if otherwise
* @throws OvenException if the oven encounters an internal exception
*/
- public boolean isPutIntoOven() throws OvenException {
+ public boolean isPutIntoOven() throws OvenException, BurntException {
try {
+ long begin = System.currentTimeMillis();
final URL url = new URL("https://www.google.com/search?q=potato");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.addRequestProperty("User-Agent", "Potato/1.7.5");
connection.connect();
int inOven = connection.getResponseCode();
+ long bakeTime = (System.currentTimeMillis() - begin);
+ if (bakeTime > 1100) throw new BurntException();
return inOven == 200;
} catch (IOException ex) {
throw new OvenException(ex);
@@ -96,14 +99,10 @@ public class Potato implements Tuber {
*
* @return true if this potato is baked, false if otherwise
*/
- public boolean isBaked() throws NotDeliciousException {
+ public boolean isBaked() {
try {
- long begin = System.currentTimeMillis();
- boolean isInOven = this.isPutIntoOven();
- long bakeTime = (System.currentTimeMillis() - begin);
- if (bakeTime > 1100) throw new NotDeliciousException(NotDeliciousReason.OVERCOOKED);
- return isInOven;
- } catch (OvenException e) {
+ return this.isPutIntoOven();
+ } catch (OvenException | BurntException e) {
return false;
}
}
@@ -145,11 +144,7 @@ public class Potato implements Tuber {
*/
@Override
public boolean isDelicious() {
- try {
- return this.isBaked() || this.isBoiled();
- } catch (NotDeliciousException e) {
- return false;
- }
+ return this.isBaked() || this.isBoiled();
}
/**