aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/drtshock/NotDeliciousException.java6
-rw-r--r--src/main/java/org/drtshock/Potato.java88
2 files changed, 77 insertions, 17 deletions
diff --git a/src/main/java/org/drtshock/NotDeliciousException.java b/src/main/java/org/drtshock/NotDeliciousException.java
index 58949b8..5ad13ec 100644
--- a/src/main/java/org/drtshock/NotDeliciousException.java
+++ b/src/main/java/org/drtshock/NotDeliciousException.java
@@ -2,7 +2,7 @@ package org.drtshock;
public class NotDeliciousException extends Exception {
- public NotDeliciousException() {
-
- }
+ public NotDeliciousException() {
+
+ }
}
diff --git a/src/main/java/org/drtshock/Potato.java b/src/main/java/org/drtshock/Potato.java
index 0aa90a8..120f88b 100644
--- a/src/main/java/org/drtshock/Potato.java
+++ b/src/main/java/org/drtshock/Potato.java
@@ -6,6 +6,9 @@ import java.net.URL;
import java.util.ArrayList;
import java.util.List;
+/**
+ * A delicious tuber that is eaten by peoples all over the world.
+ */
public class Potato implements Tuber {
private final List<Condiment> condiments = new ArrayList<Condiment>();
@@ -13,36 +16,63 @@ public class Potato implements Tuber {
public static void main(String[] args) {
final Potato potato = new Potato();
try {
- potato.prepare();
- System.out.println("Of course potato is prepared and delicious.");
+ potato.prepare();
+ System.out.println("Of course potato is prepared and delicious.");
} catch (NotDeliciousException e) {
- System.err.println("Fatal error! How could potato not be delicious?");
- return;
+ System.err.println("Fatal error! How could potato not be delicious?");
}
}
+ /**
+ * Gets the condiments on this potato.
+ *
+ * @return Mutable list of condiments
+ */
+ public List<Condiment> getCondiments() {
+ return this.condiments;
+ }
+
+ /**
+ * Prepares the potato for consumption. Adds various condiments and prints them to stdout. Ensures that the potato
+ * is delicious. If it is not, a {@link NotDeliciousException} is thrown.
+ *
+ * @throws NotDeliciousException If the potato is not delicious
+ */
public void prepare() throws NotDeliciousException {
this.addCondiments("sour cream", "chives", "butter", "crumbled bacon", "grated cheese", "ketchup", "salt", "tabasco");
this.listCondiments();
- if(!this.isDelicious()) throw NotDeliciousException();
+ if (!this.isDelicious()) throw new NotDeliciousException();
}
+ /**
+ * Adds condiments to the potato.
+ *
+ * @param names Names of the condiments to add
+ */
public void addCondiments(String... names) throws NotDeliciousException {
- synchronized (this.condiments) {
- for (String condimentName : names) {
- Condiment condiment = new Condiment(condimentName, true);
- if(!condiment.isDelicious()) throw new NotDeliciousException();
- this.condiments.add(condiment);
- }
+ for (String condimentName : names) {
+ Condiment condiment = new Condiment(condimentName, true);
+ if (!condiment.isDelicious()) throw new NotDeliciousException();
+ this.getCondiments().add(condiment);
}
}
+ /**
+ * Prints the names of the condiments on this potato to stdout.
+ *
+ * @see #getCondiments()
+ */
public void listCondiments() {
- for (Condiment condiment : this.condiments) {
+ for (Condiment condiment : this.getCondiments()) {
System.out.println(condiment.getName());
}
}
+ /**
+ * Checks if the potato is put into the oven.
+ *
+ * @return true if potato is in the oven, false if otherwise
+ */
public boolean isPutIntoOven() {
try {
final URL url = new URL("https://www.google.com/search?q=potato");
@@ -57,18 +87,38 @@ public class Potato implements Tuber {
}
}
+ /**
+ * Checks if this potato is baked. Returns the result of {@link #isPutIntoOven()}.
+ *
+ * @return true if this potato is baked, false if otherwise
+ */
public boolean isBaked() {
return this.isPutIntoOven();
}
+ /**
+ * 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();
}
+ /**
+ * Propagates a new potato.
+ *
+ * @return A new potato
+ */
+ @Override
public Tuber propagate() {
return new Potato();
}
+ /**
+ * A type of food added to tubers.
+ */
private class Condiment {
private final String name;
private final boolean delicious;
@@ -77,11 +127,21 @@ public class Potato implements Tuber {
this.name = name;
this.delicious = delicious;
}
-
+
+ /**
+ * Returns if this condiment is delicious or not.
+ *
+ * @return true if delicious, false if otherwise
+ */
public boolean isDelicious() {
- return delicious;
+ return this.delicious;
}
+ /**
+ * Gets the name of this condiment.
+ *
+ * @return Name
+ */
public String getName() {
return this.name;
}