Merge pull request #149 from spiralw/feat/vegan

Add vegan potato
This commit is contained in:
Trent Hensler
2021-08-06 18:56:18 -05:00
committed by GitHub

View File

@@ -11,10 +11,12 @@ import java.util.List;
*/ */
public class Potato implements Tuber { public class Potato implements Tuber {
private final boolean isVegan;
private final List<Condiment> condiments = new ArrayList<>(); private final List<Condiment> condiments = new ArrayList<>();
public static void main(String[] args) { public static void main(String[] args) {
final Potato potato = new Potato(); final Potato potato = new Potato(args.length == 1 && args[0].equals("--vegan"));
if (potato.isVegan) System.out.println("This potato is vegan.");
try { try {
potato.prepare(); potato.prepare();
System.out.println("Of course Potato is prepared and delicious."); System.out.println("Of course Potato is prepared and delicious.");
@@ -23,6 +25,10 @@ public class Potato implements Tuber {
} }
} }
public Potato(boolean isVegan) {
this.isVegan = isVegan;
}
/** /**
* Gets the condiments on this potato. * Gets the condiments on this potato.
* *
@@ -39,8 +45,8 @@ public class Potato implements Tuber {
* @throws NotDeliciousException If the potato is not delicious * @throws NotDeliciousException If the potato is not delicious
*/ */
public void prepare() throws NotDeliciousException { public void prepare() throws NotDeliciousException {
this.addCondiments("sour cream", "chives", "butter", "crumbled bacon", "grated cheese", "ketchup", "pepper", this.addCondiments("chives", "butter", "pepper", "salt", "tabasco", "tomatoes", "onion");
"salt", "tabasco", "tomatoes", "onion"); if (!this.isVegan) this.addCondiments("sour cream", "crumbled bacon", "grated cheese", "ketchup");
this.listCondiments(); this.listCondiments();
if (!this.isDelicious()) throw new NotDeliciousException(NotDeliciousReason.UNDERCOOKED); if (!this.isDelicious()) throw new NotDeliciousException(NotDeliciousReason.UNDERCOOKED);
} }
@@ -153,7 +159,7 @@ public class Potato implements Tuber {
*/ */
@Override @Override
public Tuber propagate() { public Tuber propagate() {
return new Potato(); return new Potato(this.isVegan);
} }
/** /**