Created
January 31, 2014 18:33
-
-
Save Bjacksonshorts/8739393 to your computer and use it in GitHub Desktop.
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
public class Cat extends Pet{ | |
public Cat(String n,int hl, int tl, int cl,int al, String ec) { | |
super(n,hl,tl,cl,al,ec); | |
} | |
public void awesome(){ | |
System.out.println("being more awesome than dog..."); | |
} | |
public void makeSound(){ | |
System.out.println("Cat is purring..."); | |
} | |
} |
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
public class Dog extends Pet{ | |
public Dog(String n,int hl, int tl, int cl,int al, String ec) { | |
super(n,hl,tl,cl,al,ec); | |
} | |
public void wag(){ | |
System.out.println("wagging tail..."); | |
} | |
public void makeSound(){ | |
System.out.println("Dog is barking..."); | |
} | |
} |
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
public abstract class Pet{ | |
private int tiredLevel; | |
private int hungryLevel; | |
private int cutenessLevel; | |
private int awesomeLevel; | |
private String eyeColor; | |
private String name; | |
public Pet(String n,int hl, int tl, int cl,int al, String ec) { | |
name = n; | |
tiredLevel = tl; | |
hungryLevel = hl; | |
cutenessLevel = cl; | |
awesomeLevel = al; | |
eyeColor = ec; | |
} | |
public void attack(){ | |
System.out.println("attacking..."); | |
} | |
public void eat(){ | |
System.out.println("eating..."); | |
} | |
public abstract void makeSound(); | |
public int getTiredLevel() { | |
return tiredLevel; | |
} | |
public int getHungryLevel() { | |
return hungryLevel; | |
} | |
public int getCutenessLevel() { | |
return cutenessLevel; | |
} | |
public int getAwesomeLevel() { | |
return awesomeLevel; | |
} | |
public String getEyeColor() { | |
return eyeColor; | |
} | |
public String getName() { | |
return name; | |
} | |
} |
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
import java.util.Scanner; | |
public class Runner{ | |
public static void main(String[] args) { | |
Cat c = new Cat("fluffy",0,0,1000,1000,"blue"); | |
Dog d = new Dog("loser",0,0,0,0,"red"); | |
Scanner scanner = new Scanner(System.in); | |
System.out.print("Enter an animal:\t"); | |
String animal = scanner.nextLine(); | |
if(animal.equals("dog")){ | |
System.out.println("The name of this animal is " + "" + d.getName()); | |
System.out.println("The tired level of this animal is " + "" + d.getTiredLevel()); | |
System.out.println("The hungry level of this animal is " + "" + d.getHungryLevel()); | |
System.out.println("The cuteness level of this animal is " + "" + d.getCutenessLevel()); | |
System.out.println("The awesome level of this animal is " + "" + d.getAwesomeLevel()); | |
System.out.println("The eye color of this animal is " + "" + d.getEyeColor()); | |
} | |
else if(animal.equals("cat")){ | |
System.out.println("The name of this animal is " + "" + c.getName()); | |
System.out.println("The tired level of this animal is " + "" + c.getTiredLevel()); | |
System.out.println("The hungry level of this animal is " + "" + c.getHungryLevel()); | |
System.out.println("The cuteness level of this animal is " + "" + c.getCutenessLevel()); | |
System.out.println("The awesome level of this animal is " + "" + c.getAwesomeLevel()); | |
System.out.println("The eye color of this animal is " + "" + c.getEyeColor()); | |
} | |
else if(animal.equals("sound")){ | |
c.makeSound(); | |
d.makeSound(); | |
} | |
else{ | |
System.out.println("That animal is not in the database yet"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment