-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82a6fc3
commit 8a8ec45
Showing
5 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
public abstract class Animal { | ||
private String name; | ||
private double weight; | ||
|
||
public Animal(String name, double weight) { | ||
this.name = name; | ||
this.weight = weight; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public double getWeight() { | ||
return weight; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public void setWeight(double weight) { | ||
this.weight = weight; | ||
} | ||
|
||
public abstract String makeNoise(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class AnimalDemo { | ||
public static void main(String[] args) { | ||
Dog myDog = new Dog("Rover", 70); | ||
Cat myCat = new Cat("Bear", 7); | ||
|
||
System.out.println(myDog.move()); | ||
System.out.println(myCat.move()); | ||
|
||
} | ||
|
||
public static void printAnimals(Animal[] animals) { | ||
for(Animal animal : animals) { | ||
System.out.println(animal.getName()); | ||
System.out.println(animal.getWeight()); | ||
System.out.println(animal.makeNoise()); | ||
System.out.println(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
public class Cat extends Animal implements IMovable { | ||
public Cat(String name, double weight) { | ||
super(name, weight); | ||
} | ||
|
||
@Override | ||
public String makeNoise() { | ||
return "Meow!"; | ||
} | ||
|
||
@Override | ||
public String move() { | ||
return "I'm stalking you, waiting on my dinner!"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
public class Dog extends Animal implements IMovable { | ||
public Dog(String name, double weight) { | ||
super(name, weight); | ||
}//end ctor | ||
|
||
@Override | ||
public String makeNoise() { | ||
return "Woof!"; | ||
} | ||
|
||
@Override | ||
public String move() { | ||
return "I'm wagging my tail and running!"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
public interface IMovable { | ||
String move(); | ||
} |