Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions AnimalZoo/src/Animal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
public abstract class Animal {

protected String m_name;
protected int m_age;
protected Habitat m_habitat;

public Animal(String name, int age, Habitat habitat) {
m_name = name;
m_age = age;
m_habitat = habitat;
}

public String getName() {
return m_name;
}

public abstract String toString();

public abstract void makeSound();
}
20 changes: 19 additions & 1 deletion AnimalZoo/src/App.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
public class App {
public static void main(String[] args) throws Exception {
System.out.println("Hello, World!");
Lion lion = new Lion("Billy", 3);
Penguin penguin = new Penguin("Bob", 2);
BlackBear blackBear = new BlackBear("Boby", 4);

System.out.println(lion.toString());
lion.makeSound();
lion.hunt();
lion.performTrick();

System.out.println(penguin.toString());
penguin.makeSound();
penguin.slide();
penguin.swim();

System.out.println(blackBear.toString());
blackBear.makeSound();
blackBear.forage();
blackBear.climbTree();
blackBear.hibernate();
}
}
36 changes: 36 additions & 0 deletions AnimalZoo/src/BlackBear.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import java.util.Random;

public class BlackBear extends Animal{
public BlackBear(String name, int age) {
super(name, age, Habitat.FOREST);
}

@Override
public String toString() {
return (m_name + " the Black Bear lives in the " + m_habitat + " where it is " + m_habitat.getTemp() + " degrees fahrenheit and " + m_name + " is " + m_age + " years old");
}

@Override
public void makeSound() {
Random soundRand = new Random();
int m_check = soundRand.nextInt(1, 3);
if(m_check == 1) {
System.out.println(m_name + " the Black bear growels loudly");
}
else if(m_check == 2) {
System.out.println(m_name + " the Black Bear makes a terrifying roar");
}
}

public void forage() {
System.out.println(m_name + " the Black Bear gets berries from a near by bush and eats it right there.");
}

public void climbTree() {
System.out.println(m_name + " the Black Bear climbs a nearby tree");
}

public void hibernate() {
System.out.println(m_name + " the Black Bear goes to sleep");
}
}
15 changes: 15 additions & 0 deletions AnimalZoo/src/Habitat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public enum Habitat {
SAVANNAH(85),
ARTIC(-20),
FOREST(60);

private int m_temp;

private Habitat(int tempature) {
m_temp = tempature;
}

public int getTemp() {
return m_temp;
}
}
44 changes: 44 additions & 0 deletions AnimalZoo/src/Lion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import java.util.Random;

public class Lion extends Animal implements Trainable {

public Lion(String name, int age) {
super(name, age, Habitat.SAVANNAH);
}

@Override
public String toString() {
return (m_name + " the lion lives in the " + m_habitat + " where it is " + m_habitat.getTemp() + " degrees fahrenheit and " + m_name + " is " + m_age + " years old");
}

@Override
public void makeSound() {
Random soundRand = new Random();
int m_check = soundRand.nextInt(1, 3);
if(m_check == 1) {
System.out.println(m_name + " the Lion roars loudly");
}
else if(m_check == 2) {
System.out.println(m_name + " the Lion meows softly");
}
}

@Override
public void performTrick() {
Random soundRand = new Random();
int m_check = soundRand.nextInt(1, 4);
if(m_check == 1) {
System.out.println(m_name + " the Lion jumps through a hoop of fire");
}
else if(m_check == 2) {
System.out.println(m_name + " the Lion eats a chunk of meat in under 3 seconds a new rocord for " + m_name);
}
else if(m_check == 3) {
System.out.println(m_name + " the lion eats a chunk lf meat in under 5 seconds " + m_name + " looks sad");
}
}

public void hunt() {
System.out.println(m_name + " the lion kills one of the penguins and eats it right there.");
}
}
33 changes: 33 additions & 0 deletions AnimalZoo/src/Penguin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import java.util.Random;

public class Penguin extends Animal{

public Penguin(String name, int age) {
super(name, age, Habitat.ARTIC);
}

@Override
public String toString() {
return (m_name + " the Penguin lives in the " + m_habitat + " where it is " + m_habitat.getTemp() + " degrees fahrenheit and " + m_name + " is " + m_age + " years old");
}

@Override
public void makeSound() {
Random soundRand = new Random();
int m_check = soundRand.nextInt(1, 3);
if(m_check == 1) {
System.out.println(m_name + " the Penguin honks");
}
else if(m_check == 2) {
System.out.println(m_name + " the Penguin stares into your soul and says nothing, the farts");
}
}

public void swim() {
System.out.println(m_name + " swims in a figure 8");
}

public void slide() {
System.out.println(m_name + " slides gracefully on its belly");
}
}
3 changes: 3 additions & 0 deletions AnimalZoo/src/Trainable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public interface Trainable {
public abstract void performTrick();
}