mirror of
https://github.com/UnlegitDqrk/Potato.git
synced 2025-10-02 06:30:15 +02:00
Add BurntException for baking too long
This commit is contained in:
@@ -9,4 +9,8 @@ public class BurntException extends Exception {
|
|||||||
super("Potato is badly burnt by trying to boil it at " + degrees + " degrees!!");
|
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!");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -6,7 +6,6 @@ package org.drtshock;
|
|||||||
public enum NotDeliciousReason {
|
public enum NotDeliciousReason {
|
||||||
|
|
||||||
UNDERCOOKED,
|
UNDERCOOKED,
|
||||||
OVERCOOKED,
|
|
||||||
NOT_DELICIOUS_CONDIMENT,
|
NOT_DELICIOUS_CONDIMENT,
|
||||||
EXPIRED_CONDIMENT
|
EXPIRED_CONDIMENT
|
||||||
|
|
||||||
|
@@ -77,14 +77,17 @@ public class Potato implements Tuber {
|
|||||||
* @return true if potato is in the oven, false if otherwise
|
* @return true if potato is in the oven, false if otherwise
|
||||||
* @throws OvenException if the oven encounters an internal exception
|
* @throws OvenException if the oven encounters an internal exception
|
||||||
*/
|
*/
|
||||||
public boolean isPutIntoOven() throws OvenException {
|
public boolean isPutIntoOven() throws OvenException, BurntException {
|
||||||
try {
|
try {
|
||||||
|
long begin = System.currentTimeMillis();
|
||||||
final URL url = new URL("https://www.google.com/search?q=potato");
|
final URL url = new URL("https://www.google.com/search?q=potato");
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
connection.setRequestMethod("GET");
|
connection.setRequestMethod("GET");
|
||||||
connection.addRequestProperty("User-Agent", "Potato/1.7.5");
|
connection.addRequestProperty("User-Agent", "Potato/1.7.5");
|
||||||
connection.connect();
|
connection.connect();
|
||||||
int inOven = connection.getResponseCode();
|
int inOven = connection.getResponseCode();
|
||||||
|
long bakeTime = (System.currentTimeMillis() - begin);
|
||||||
|
if (bakeTime > 1100) throw new BurntException();
|
||||||
return inOven == 200;
|
return inOven == 200;
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw new OvenException(ex);
|
throw new OvenException(ex);
|
||||||
@@ -96,14 +99,10 @@ public class Potato implements Tuber {
|
|||||||
*
|
*
|
||||||
* @return true if this potato is baked, false if otherwise
|
* @return true if this potato is baked, false if otherwise
|
||||||
*/
|
*/
|
||||||
public boolean isBaked() throws NotDeliciousException {
|
public boolean isBaked() {
|
||||||
try {
|
try {
|
||||||
long begin = System.currentTimeMillis();
|
return this.isPutIntoOven();
|
||||||
boolean isInOven = this.isPutIntoOven();
|
} catch (OvenException | BurntException e) {
|
||||||
long bakeTime = (System.currentTimeMillis() - begin);
|
|
||||||
if (bakeTime > 1100) throw new NotDeliciousException(NotDeliciousReason.OVERCOOKED);
|
|
||||||
return isInOven;
|
|
||||||
} catch (OvenException e) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -145,11 +144,7 @@ public class Potato implements Tuber {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isDelicious() {
|
public boolean isDelicious() {
|
||||||
try {
|
|
||||||
return this.isBaked() || this.isBoiled();
|
return this.isBaked() || this.isBoiled();
|
||||||
} catch (NotDeliciousException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user