diff --git a/README.md b/README.md index 3e3b1da..f2e3747 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# The Circus Project +# The circus.Circus Project diff --git a/src/main/java/Animal.java b/src/main/java/Animal.java deleted file mode 100644 index 956bc52..0000000 --- a/src/main/java/Animal.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Animal { - - public String speak(){ - return null; - } -} diff --git a/src/main/java/circus/Animal.java b/src/main/java/circus/Animal.java new file mode 100644 index 0000000..2b1348b --- /dev/null +++ b/src/main/java/circus/Animal.java @@ -0,0 +1,5 @@ +package circus; + +public abstract class Animal implements Asset { + public abstract String speak(); +} diff --git a/src/main/java/circus/Asset.java b/src/main/java/circus/Asset.java new file mode 100644 index 0000000..2b1afd1 --- /dev/null +++ b/src/main/java/circus/Asset.java @@ -0,0 +1,5 @@ +package circus; + +public interface Asset { + int getValue(); +} diff --git a/src/main/java/Bird.java b/src/main/java/circus/Bird.java similarity index 54% rename from src/main/java/Bird.java rename to src/main/java/circus/Bird.java index 1125ec1..f10b9e2 100644 --- a/src/main/java/Bird.java +++ b/src/main/java/circus/Bird.java @@ -1,4 +1,6 @@ -public class Bird extends Animal { +package circus; + +public abstract class Bird extends Animal { public void fly() { System.out.println("Whee ..."); } diff --git a/src/main/java/Cannon.java b/src/main/java/circus/Cannon.java similarity index 92% rename from src/main/java/Cannon.java rename to src/main/java/circus/Cannon.java index 7b0b252..a9799bf 100644 --- a/src/main/java/Cannon.java +++ b/src/main/java/circus/Cannon.java @@ -1,3 +1,5 @@ +package circus; + public class Cannon extends Equipment { public Cannon(int purchasePrice) { diff --git a/src/main/java/Circus.java b/src/main/java/circus/Circus.java similarity index 61% rename from src/main/java/Circus.java rename to src/main/java/circus/Circus.java index d15338c..5618443 100644 --- a/src/main/java/Circus.java +++ b/src/main/java/circus/Circus.java @@ -1,3 +1,5 @@ +package circus; + public class Circus { private static Animal[] animals = { new Duck(), @@ -16,25 +18,28 @@ private static void makeAnimalsTalk() { } } - private static int calculateValue(Equipment[] equipments) { + private static int calculateValue(Asset[] assets) { int total = 0; - for (Equipment e : equipments) { - if (e.getValue() <= 5) { - System.out.println("Ignoring low value item: " + e.getValue()); - } else { - total += e.getValue(); - System.out.println("Adding item value: " + e.getValue()); - // some - // more - // code - // here ... + for (Asset a : assets) { + if (a.getValue() <= 5) { + System.out.println("Ignoring low value item: " + a.getValue()); + continue; } + + total += a.getValue(); + System.out.println("Adding item value: " + a.getValue()); + // some + // more + // code + // here ... } + return total; - } +} public static void main(String[] args) { makeAnimalsTalk(); System.out.println("Total value of equipments " + calculateValue(equipments)); + System.out.println("Total value of animals " + calculateValue(animals)); } } diff --git a/src/main/java/Duck.java b/src/main/java/circus/Duck.java similarity index 67% rename from src/main/java/Duck.java rename to src/main/java/circus/Duck.java index 7492ccf..3037afe 100644 --- a/src/main/java/Duck.java +++ b/src/main/java/circus/Duck.java @@ -1,3 +1,5 @@ +package circus; + public class Duck extends Bird { @Override public String speak() { @@ -6,10 +8,15 @@ public String speak() { @Override public String toString() { - return "I'm a Duck"; + return "I'm a circus.Duck"; } public void swim() { System.out.println("I'm swimming..."); } + + @Override + public int getValue() { + return 0; + } } diff --git a/src/main/java/Equipment.java b/src/main/java/circus/Equipment.java similarity index 73% rename from src/main/java/Equipment.java rename to src/main/java/circus/Equipment.java index 6ef8ffc..1c77cff 100644 --- a/src/main/java/Equipment.java +++ b/src/main/java/circus/Equipment.java @@ -1,4 +1,6 @@ -public abstract class Equipment { +package circus; + +public abstract class Equipment implements Asset { protected int purchasePrice; public Equipment(int purchasePrice) { diff --git a/src/main/java/Ladder.java b/src/main/java/circus/Ladder.java similarity index 92% rename from src/main/java/Ladder.java rename to src/main/java/circus/Ladder.java index d26ca7a..5282e29 100644 --- a/src/main/java/Ladder.java +++ b/src/main/java/circus/Ladder.java @@ -1,3 +1,5 @@ +package circus; + public class Ladder extends Equipment { public Ladder(int purchasePrice) { diff --git a/src/main/java/Parrot.java b/src/main/java/circus/Parrot.java similarity index 71% rename from src/main/java/Parrot.java rename to src/main/java/circus/Parrot.java index 30695a5..6bc461a 100644 --- a/src/main/java/Parrot.java +++ b/src/main/java/circus/Parrot.java @@ -1,3 +1,5 @@ +package circus; + public class Parrot extends Bird { @Override public String speak() { @@ -8,4 +10,9 @@ public String speak() { public String toString() { return "I'm a parrot"; } + + @Override + public int getValue() { + return 0; + } } diff --git a/src/main/java/Trainer.java b/src/main/java/circus/Trainer.java similarity index 71% rename from src/main/java/Trainer.java rename to src/main/java/circus/Trainer.java index 67750e6..eb2a915 100644 --- a/src/main/java/Trainer.java +++ b/src/main/java/circus/Trainer.java @@ -1,3 +1,5 @@ +package circus; + public class Trainer { public static void main(String[] args) { Duck d = new Duck(); @@ -7,13 +9,13 @@ public static void main(String[] args) { System.out.println(a.speak()); Duck d2 = (Duck) a; // downcasting train(new Duck()); - // train(new Parrot()); - Animal a2 = new Animal(); - Bird b2 = new Bird(); + // train(new circus.Parrot()); } private static void train(Bird bird) { - Duck d = (Duck) bird; - d.swim(); + if(bird instanceof Duck) { + Duck d = (Duck) bird; + d.swim(); + } } } diff --git a/text-ui-test/EXPECTED.txt b/text-ui-test/EXPECTED.txt index 0cab7db..79faccf 100644 --- a/text-ui-test/EXPECTED.txt +++ b/text-ui-test/EXPECTED.txt @@ -1,4 +1,4 @@ -I'm a Duck +I'm a circus.Duck Quack Quack I'm a parrot Polly wants a cracker diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 1d6bed0..f64997f 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -7,7 +7,7 @@ REM delete output from previous run del ACTUAL.TXT REM compile the code into the bin folder -javac -cp ..\src -Xlint:none -d ..\bin ..\src\main\java\*.java +javac -cp ..\src -Xlint:none -d ..\bin ..\src\main\java\circus\*.java IF ERRORLEVEL 1 ( echo ********** BUILD FAILURE ********** exit /b 1 @@ -15,7 +15,7 @@ IF ERRORLEVEL 1 ( REM no error here, errorlevel == 0 REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT -java -classpath ..\bin Circus > ACTUAL.TXT +java -classpath ..\bin circus.Circus > ACTUAL.TXT REM compare the output to the expected output FC ACTUAL.TXT EXPECTED.TXT \ No newline at end of file diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh index 3d5c6bd..14ba22f 100644 --- a/text-ui-test/runtest.sh +++ b/text-ui-test/runtest.sh @@ -20,7 +20,7 @@ then fi # run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT -java -classpath ../bin Circus > ACTUAL.TXT +java -classpath ../bin circus.Circus > ACTUAL.TXT # compare the output to the expected output diff ACTUAL.TXT EXPECTED.TXT