From 36ba3f1a66a17ddbbde7fa042df7bee6daa3ed4b Mon Sep 17 00:00:00 2001 From: Akshay Narayan Date: Fri, 10 Feb 2023 13:24:23 +0800 Subject: [PATCH 1/5] Add names to animals --- src/main/java/circus/Circus.java | 4 ++-- src/main/java/circus/Trainer.java | 4 ++-- src/main/java/circus/animal/Animal.java | 1 + src/main/java/circus/animal/Duck.java | 18 +++++++++++------- src/main/java/circus/animal/Parrot.java | 12 ++++++++---- 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/main/java/circus/Circus.java b/src/main/java/circus/Circus.java index e29b8c3..d438b99 100644 --- a/src/main/java/circus/Circus.java +++ b/src/main/java/circus/Circus.java @@ -9,8 +9,8 @@ public class Circus { private static Animal[] animals = { - new Duck(), - new Parrot() + new Duck("Drake"), + new Parrot("Polly") }; private static Equipment[] equipments = { new Ladder(50), diff --git a/src/main/java/circus/Trainer.java b/src/main/java/circus/Trainer.java index eb3e711..43d6e69 100644 --- a/src/main/java/circus/Trainer.java +++ b/src/main/java/circus/Trainer.java @@ -7,7 +7,7 @@ public class Trainer { public static void main(String[] args) { - Duck d = new Duck(); + Duck d = new Duck("Donald"); getToSpeak(d); Bird b = (Bird) d; // upcasting @@ -19,7 +19,7 @@ public static void main(String[] args) { Duck d2 = (Duck) a; // downcasting getToSpeak(d2); - train(new Duck()); + train(new Duck("Daisy")); // train(new animal.Parrot()); } diff --git a/src/main/java/circus/animal/Animal.java b/src/main/java/circus/animal/Animal.java index dc2422d..859a50d 100644 --- a/src/main/java/circus/animal/Animal.java +++ b/src/main/java/circus/animal/Animal.java @@ -4,5 +4,6 @@ public abstract class Animal implements Asset { + public String name; public abstract String speak(); } diff --git a/src/main/java/circus/animal/Duck.java b/src/main/java/circus/animal/Duck.java index edac6d2..e9baab7 100644 --- a/src/main/java/circus/animal/Duck.java +++ b/src/main/java/circus/animal/Duck.java @@ -3,20 +3,24 @@ public class Duck extends Bird { @Override public String speak() { - return "Quack Quack"; - } - - @Override - public int getValue() { - return 10; + return toString() + " Quack Quack"; } @Override public String toString() { - return "I'm a Duck"; + return "I'm " + name + ". I am a Duck!"; } public void swim() { System.out.println("I'm swimming..."); } + + @Override + public int getValue() { + return 10; + } + + public Duck(String name) { + this.name = name; + } } diff --git a/src/main/java/circus/animal/Parrot.java b/src/main/java/circus/animal/Parrot.java index 6432b2a..78efbb5 100644 --- a/src/main/java/circus/animal/Parrot.java +++ b/src/main/java/circus/animal/Parrot.java @@ -3,7 +3,12 @@ public class Parrot extends Bird { @Override public String speak() { - return "Polly wants a cracker"; + return name + " wants a cracker"; + } + + @Override + public String toString() { + return "My name is " + name + ". I am a Parrot!"; } @Override @@ -11,8 +16,7 @@ public int getValue() { return 20; } - @Override - public String toString() { - return "I'm a parrot"; + public Parrot(String name) { + this.name = name; } } From 9d37781c8c3c083ab90a0ee8cf80fe29505bd476 Mon Sep 17 00:00:00 2001 From: Akshay Narayan Date: Fri, 10 Feb 2023 13:24:33 +0800 Subject: [PATCH 2/5] Add tiger to circus --- src/main/java/circus/animal/Tiger.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/main/java/circus/animal/Tiger.java diff --git a/src/main/java/circus/animal/Tiger.java b/src/main/java/circus/animal/Tiger.java new file mode 100644 index 0000000..23571ba --- /dev/null +++ b/src/main/java/circus/animal/Tiger.java @@ -0,0 +1,22 @@ +package circus.animal; + +public class Tiger extends Animal { + @Override + public String toString() { + return "My name is " + name + ". I am a majestic Tiger!"; + } + + @Override + public int getValue() { + return 100; + } + + @Override + public String speak() { + return toString() + ". I don't speak; I ROARRR!!!!"; + } + + public Tiger(String name) { + this.name = name; + } +} From d2d073b0f3a4f1c750736f500433a8399ebfef1e Mon Sep 17 00:00:00 2001 From: Akshay Narayan Date: Fri, 10 Feb 2023 13:24:42 +0800 Subject: [PATCH 3/5] Add elephant to circus --- src/main/java/circus/animal/Elephant.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/java/circus/animal/Elephant.java diff --git a/src/main/java/circus/animal/Elephant.java b/src/main/java/circus/animal/Elephant.java new file mode 100644 index 0000000..1fe1a55 --- /dev/null +++ b/src/main/java/circus/animal/Elephant.java @@ -0,0 +1,23 @@ +package circus.animal; + +public class Elephant extends Animal { + @Override + public String toString() { + return "My name is " + name + ". I am an Elephant!"; + } + + @Override + public int getValue() { + return 100; + } + + @Override + public String speak() { + return toString() + ". I am the strongest"; + } + + public Elephant(String name) { + this.name = name; + } + +} From d09d018f84761410c8fd72b5641c216aba651f57 Mon Sep 17 00:00:00 2001 From: Akshay Narayan Date: Fri, 10 Feb 2023 13:30:03 +0800 Subject: [PATCH 4/5] Add tiger Tai Lung to Circus --- src/main/java/circus/Circus.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/circus/Circus.java b/src/main/java/circus/Circus.java index d438b99..fd4d84f 100644 --- a/src/main/java/circus/Circus.java +++ b/src/main/java/circus/Circus.java @@ -3,6 +3,7 @@ import circus.animal.Animal; import circus.animal.Duck; import circus.animal.Parrot; +import circus.animal.Tiger; import circus.stuff.Cannon; import circus.stuff.Equipment; import circus.stuff.Ladder; @@ -10,7 +11,8 @@ public class Circus { private static Animal[] animals = { new Duck("Drake"), - new Parrot("Polly") + new Parrot("Polly"), + new Tiger("Tai Lung") }; private static Equipment[] equipments = { new Ladder(50), From c63c77cef147777b34233ab03985c0f14f15ee06 Mon Sep 17 00:00:00 2001 From: Akshay Narayan Date: Fri, 10 Feb 2023 13:34:24 +0800 Subject: [PATCH 5/5] Update tests --- text-ui-test/EXPECTED.txt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/text-ui-test/EXPECTED.txt b/text-ui-test/EXPECTED.txt index 19da732..91a21b8 100644 --- a/text-ui-test/EXPECTED.txt +++ b/text-ui-test/EXPECTED.txt @@ -1,10 +1,13 @@ -I'm a Duck -Quack Quack -I'm a parrot +I'm Drake. I am a Duck! +I'm Drake. I am a Duck! Quack Quack +My name is Polly. I am a Parrot! Polly wants a cracker +My name is Tai Lung. I am a majestic Tiger! +My name is Tai Lung. I am a majestic Tiger!. I don't speak; I ROARRR!!!! Adding item value: 10 Adding item value: 20 -Total value of animals 30 +Adding item value: 100 +Total value of animals 130 Adding item value: 25 Ignoring low value item: 1 Adding item value: 33