Add overcooked reason, rename raw to undercooked

This commit is contained in:
Trophonix
2017-06-21 09:13:23 -05:00
parent a016415cfd
commit c69264a552
3 changed files with 19 additions and 7 deletions

View File

@@ -14,4 +14,7 @@ public class NotDeliciousException extends Exception {
this.notDeliciousReason = notDeliciousReason; this.notDeliciousReason = notDeliciousReason;
} }
public NotDeliciousReason getReason() {
return notDeliciousReason;
}
} }

View File

@@ -5,7 +5,8 @@ package org.drtshock;
*/ */
public enum NotDeliciousReason { public enum NotDeliciousReason {
RAW, UNDERCOOKED,
OVERCOOKED,
NOT_DELICIOUS_CONDIMENT, NOT_DELICIOUS_CONDIMENT,
EXPIRED_CONDIMENT EXPIRED_CONDIMENT

View File

@@ -20,7 +20,7 @@ public class Potato implements Tuber {
potato.prepare(); potato.prepare();
System.out.println("Of course Potato is prepared and delicious."); System.out.println("Of course Potato is prepared and delicious.");
} catch (NotDeliciousException e) { } catch (NotDeliciousException e) {
System.err.println("Fatal error! How could Potato not be delicious?"); System.err.println("Fatal error! How could Potato not be delicious?\nReason: " + e.getReason());
} }
} }
@@ -43,7 +43,7 @@ public class Potato implements Tuber {
this.addCondiments("sour cream", "chives", "butter", "crumbled bacon", "grated cheese", "ketchup", "pepper", this.addCondiments("sour cream", "chives", "butter", "crumbled bacon", "grated cheese", "ketchup", "pepper",
"salt", "tabasco", "tomatoes"); "salt", "tabasco", "tomatoes");
this.listCondiments(); this.listCondiments();
if (!this.isDelicious()) throw new NotDeliciousException(NotDeliciousReason.RAW); if (!this.isDelicious()) throw new NotDeliciousException(NotDeliciousReason.UNDERCOOKED);
} }
/** /**
@@ -96,9 +96,13 @@ 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() { public boolean isBaked() throws NotDeliciousException {
try { try {
return this.isPutIntoOven(); 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) { } catch (OvenException e) {
return false; return false;
} }
@@ -109,7 +113,7 @@ 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 isCooked() { public boolean isBoiled() {
try { try {
return this.hasBeenBoiledInWater(); return this.hasBeenBoiledInWater();
} catch (BurntException e) { } catch (BurntException e) {
@@ -141,7 +145,11 @@ public class Potato implements Tuber {
*/ */
@Override @Override
public boolean isDelicious() { public boolean isDelicious() {
return this.isBaked() || this.isCooked(); try {
return this.isBaked() || this.isBoiled();
} catch (NotDeliciousException e) {
return false;
}
} }
/** /**