From 200f803e662d5cefce24ea1db9c060916f5ee5f6 Mon Sep 17 00:00:00 2001 From: KutikiPlayz Date: Mon, 3 Apr 2023 04:03:46 -0600 Subject: [PATCH 1/2] "not washed properly" not delicious reason --- .../java/org/drtshock/NotDeliciousReason.java | 3 +- src/main/java/org/drtshock/Potato.java | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/drtshock/NotDeliciousReason.java b/src/main/java/org/drtshock/NotDeliciousReason.java index d093f08c..73774192 100644 --- a/src/main/java/org/drtshock/NotDeliciousReason.java +++ b/src/main/java/org/drtshock/NotDeliciousReason.java @@ -8,6 +8,7 @@ public enum NotDeliciousReason { UNDERCOOKED, OVERCOOKED, NOT_DELICIOUS_CONDIMENT, - EXPIRED_CONDIMENT + EXPIRED_CONDIMENT, + NOT_WASHED } diff --git a/src/main/java/org/drtshock/Potato.java b/src/main/java/org/drtshock/Potato.java index eeb051e4..8476e490 100644 --- a/src/main/java/org/drtshock/Potato.java +++ b/src/main/java/org/drtshock/Potato.java @@ -5,6 +5,7 @@ import java.net.URL; import java.util.ArrayList; import java.util.List; +import java.util.Random; /** * A delicious tuber that is eaten by various peoples all over the world. @@ -48,6 +49,7 @@ public void prepare() throws NotDeliciousException { this.addCondiments("chives", "butter", "pepper", "salt", "tabasco", "tomatoes", "onion"); if (!this.isVegan) this.addCondiments("sour cream", "crumbled bacon", "grated cheese", "ketchup"); this.listCondiments(); + if (!this.hasBeenWashed()) throw new NotDeliciousException(NotDeliciousReason.NOT_WASHED); if (!this.isDelicious()) throw new NotDeliciousException(NotDeliciousReason.UNDERCOOKED); } @@ -162,6 +164,35 @@ public Tuber propagate() { return new Potato(this.isVegan); } + public boolean hasBeenWashed() { + String washMethod = ""; + float[] washTimeRange = {0, 0}; // in seconds + switch (new Random().nextInt(3)) { + case 0: + washMethod = "quick rinse"; + washTimeRange[0] = 10; + washTimeRange[1] = 15; + break; + case 1: + washMethod = "scrubbing"; + washTimeRange[0] = 30; + washTimeRange[1] = 60; + break; + case 2: + washMethod = "soaking"; + washTimeRange[0] = 300; + washTimeRange[1] = 600; + break; + } + float washTime = (float) (Math.random() * washTimeRange[1]); // in seconds + System.out.println("wash method: " + washMethod); + System.out.println("wash time: " + washTime); + if (washTime <= washTimeRange[0]) { // not washed long enough + return false; + } + return true; + } + /** * A type of food added to tubers. */ From 5ff8da0f39748bf99e105aec78d1db377b8a0127 Mon Sep 17 00:00:00 2001 From: KutikiPlayz Date: Mon, 3 Apr 2023 05:05:10 -0600 Subject: [PATCH 2/2] change wash method to an enum --- src/main/java/org/drtshock/Potato.java | 48 ++++++++++++-------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/drtshock/Potato.java b/src/main/java/org/drtshock/Potato.java index 8476e490..98d2a15f 100644 --- a/src/main/java/org/drtshock/Potato.java +++ b/src/main/java/org/drtshock/Potato.java @@ -46,10 +46,10 @@ public List getCondiments() { * @throws NotDeliciousException If the potato is not delicious */ public void prepare() throws NotDeliciousException { + if (!isWashed()) throw new NotDeliciousException(NotDeliciousReason.NOT_WASHED); this.addCondiments("chives", "butter", "pepper", "salt", "tabasco", "tomatoes", "onion"); if (!this.isVegan) this.addCondiments("sour cream", "crumbled bacon", "grated cheese", "ketchup"); this.listCondiments(); - if (!this.hasBeenWashed()) throw new NotDeliciousException(NotDeliciousReason.NOT_WASHED); if (!this.isDelicious()) throw new NotDeliciousException(NotDeliciousReason.UNDERCOOKED); } @@ -164,33 +164,29 @@ public Tuber propagate() { return new Potato(this.isVegan); } - public boolean hasBeenWashed() { - String washMethod = ""; - float[] washTimeRange = {0, 0}; // in seconds - switch (new Random().nextInt(3)) { - case 0: - washMethod = "quick rinse"; - washTimeRange[0] = 10; - washTimeRange[1] = 15; - break; - case 1: - washMethod = "scrubbing"; - washTimeRange[0] = 30; - washTimeRange[1] = 60; - break; - case 2: - washMethod = "soaking"; - washTimeRange[0] = 300; - washTimeRange[1] = 600; - break; + private boolean isWashed() { + return WashMethod.values()[new Random().nextInt(WashMethod.values().length)].hasBeenWashed(); + } + + private enum WashMethod { + QUICK_RINSE(10, 15), + SCRUBBING(30, 60), + SOAKING(300, 600); + + private final int minWashTime; + private final int maxWashTime; + + WashMethod(int minWashTime, int maxWashTime) { + this.minWashTime = minWashTime; + this.maxWashTime = maxWashTime; } - float washTime = (float) (Math.random() * washTimeRange[1]); // in seconds - System.out.println("wash method: " + washMethod); - System.out.println("wash time: " + washTime); - if (washTime <= washTimeRange[0]) { // not washed long enough - return false; + + public boolean hasBeenWashed() { + int washTime = (int) (Math.random() * maxWashTime); + System.out.println("Wash method: " + this.toString()); + System.out.println("Wash time: " + washTime); + return washTime > minWashTime; } - return true; } /**