Skip to content

Instantly share code, notes, and snippets.

@Bjacksonshorts
Created January 31, 2014 18:33
Show Gist options
  • Save Bjacksonshorts/8739393 to your computer and use it in GitHub Desktop.
Save Bjacksonshorts/8739393 to your computer and use it in GitHub Desktop.
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...");
}
}
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...");
}
}
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;
}
}
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