Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
yizt73 committed Feb 10, 2023
2 parents 221e8c1 + c63c77c commit 364501e
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 19 deletions.
6 changes: 4 additions & 2 deletions src/main/java/circus/Circus.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
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;

public class Circus {
private static Animal[] animals = {
new Duck(),
new Parrot()
new Duck("Drake"),
new Parrot("Polly"),
new Tiger("Tai Lung")
};
private static Equipment[] equipments = {
new Ladder(50),
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/circus/Trainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/circus/animal/Animal.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@

public abstract class Animal implements Asset {

public String name;
public abstract String speak();
}
18 changes: 11 additions & 7 deletions src/main/java/circus/animal/Duck.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
23 changes: 23 additions & 0 deletions src/main/java/circus/animal/Elephant.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
12 changes: 8 additions & 4 deletions src/main/java/circus/animal/Parrot.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
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
public int getValue() {
return 20;
}

@Override
public String toString() {
return "I'm a parrot";
public Parrot(String name) {
this.name = name;
}
}
22 changes: 22 additions & 0 deletions src/main/java/circus/animal/Tiger.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
11 changes: 7 additions & 4 deletions text-ui-test/EXPECTED.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 364501e

Please sign in to comment.