Skip to content

Commit

Permalink
Add all living beings in the circus
Browse files Browse the repository at this point in the history
  • Loading branch information
okkhoy committed Feb 3, 2023
1 parent 6b52a82 commit 911af68
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/Animal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class Animal {

public String speak() {
return null;
}
}
5 changes: 5 additions & 0 deletions src/main/java/Bird.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class Bird extends Animal {
public void fly() {
System.out.println("Whee ...");
}
}
40 changes: 40 additions & 0 deletions src/main/java/Circus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
public class Circus {
private static Animal[] animals = {
new Duck(),
new Parrot()
};
private static Equipment[] equipments = {
new Ladder(50),
new Cannon(5),
new Cannon(100)
};

private static void makeAnimalsTalk() {
for (Animal a : animals) {
System.out.println(a);
System.out.println(a.speak());
}
}

private static int calculateValue(Equipment[] equipments) {
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 ...
}
}
return total;
}

public static void main(String[] args) {
makeAnimalsTalk();
System.out.println("Total value of equipments " + calculateValue(equipments));
}
}
15 changes: 15 additions & 0 deletions src/main/java/Duck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class Duck extends Bird {
@Override
public String speak() {
return "Quack Quack";
}

@Override
public String toString() {
return "I'm a Duck";
}

public void swim() {
System.out.println("I'm swimming...");
}
}
11 changes: 11 additions & 0 deletions src/main/java/Parrot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class Parrot extends Bird {
@Override
public String speak() {
return "Polly wants a cracker";
}

@Override
public String toString() {
return "I'm a parrot";
}
}

0 comments on commit 911af68

Please sign in to comment.