From 70368c1a73887f50c8bfca87845b26dda37860e3 Mon Sep 17 00:00:00 2001 From: xMrMysteri0us Date: Sun, 28 Sep 2014 13:59:04 +0200 Subject: [PATCH] Add NotDeliciousException --- .../java/org/drtshock/NotDeliciousException.java | 8 ++++++++ src/main/java/org/drtshock/Potato.java | 13 +++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/drtshock/NotDeliciousException.java diff --git a/src/main/java/org/drtshock/NotDeliciousException.java b/src/main/java/org/drtshock/NotDeliciousException.java new file mode 100644 index 0000000..58949b8 --- /dev/null +++ b/src/main/java/org/drtshock/NotDeliciousException.java @@ -0,0 +1,8 @@ +package org.drtshock; + +public class NotDeliciousException extends Exception { + + public NotDeliciousException() { + + } +} diff --git a/src/main/java/org/drtshock/Potato.java b/src/main/java/org/drtshock/Potato.java index b418664..173340a 100644 --- a/src/main/java/org/drtshock/Potato.java +++ b/src/main/java/org/drtshock/Potato.java @@ -12,14 +12,19 @@ public class Potato implements Tuber { public static void main(String[] args) { final Potato potato = new Potato(); - if (potato.prepare()) System.out.println("Of course potato is prepared and delicious."); - else System.err.println("Fatal error! How could potato not be delicious?"); + try { + 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; + } } - public boolean prepare() { + public void prepare() throws NotDeliciousException { this.addCondiments("sour cream", "chives", "butter", "crumbled bacon", "grated cheese", "ketchup", "salt", "tabasco"); this.listCondiments(); - return this.isDelicious(); + if(!this.isDelicious()) throw NotDeliciousException(); } public void addCondiments(String... names) {