abstract class Animal{
protected boolean mammal;
protected boolean carnivorous;
protected int mood;
Animal(boolean mammal,boolean carnivorous){
this.mammal = mammal;
this.carnivorous = carnivorous;
}
abstract void isMammal();
abstract void isCarnivorous();
void setMood(int newValue){
mood = newValue;
}
abstract void getMood();
abstract void sayHello();
}
interface LandAnimal{
void getNumberOfLegs();
}
interface WaterAnimal{
void hasGills();
void laysEggs();
}
class Dog extends Animal implements LandAnimal{
private int legs;
Dog(){
super(true,true);
legs = 4;
}
void isMammal(){
System.out.println("狗" + mammal + "哺乳动物");
}
void isCarnivorous(){
System.out.println("狗" + mammal + "肉食动物");
}
void setMood(int newValue){
mood = newValue;
}
void getMood(){
if(mood == 1)
System.out.println("狗高兴时旺旺叫...");
else
System.out.println("狗不高兴时乱咬人...");
}
void sayHello(){
System.out.println("狗跟人打招呼是甩甩尾...");
}
public void getNumberOfLegs(){
System.out.println("狗有" + legs + "条腿");
}
void showInfo(){
System.out.println("-- * -- * -- * -- * -- * -- * -- * -- * --");
isMammal();
isCarnivorous();
getNumberOfLegs();
getMood();
sayHello();
System.out.println("-- * -- * -- * -- * -- * -- * -- * -- * --");
}
}
class Cat extends Animal implements LandAnimal{
private int legs;
Cat(){
super(true,true);
legs = 4;
}
void isMammal(){
System.out.println("猫" + mammal + "哺乳动物");
}
void isCarnivorous(){
System.out.println("猫" + mammal + "肉食动物");
}
void setMood(int newValue){
mood = newValue;
}
void getMood(){
if(mood == 1)
System.out.println("猫高兴时会爬树...");
else
System.out.println("猫不高兴时捉老鼠...");
}
void sayHello(){
System.out.println("猫跟人打招呼是猫咪叫...");
}
public void getNumberOfLegs(){
System.out.println("猫有" + legs + "条腿");
}
void showInfo(){
System.out.println("-- * -- * -- * -- * -- * -- * -- * -- * --");
isMammal();
isCarnivorous();
getNumberOfLegs();
getMood();
sayHello();
System.out.println("-- * -- * -- * -- * -- * -- * -- * -- * --");
}
}
class Frog extends Animal implements WaterAnimal{
private int legs;
Frog(){
super(false,false);
legs = 2;
}
void isMammal(){
System.out.println("青蛙" + mammal + "哺乳动物");
}
void isCarnivorous(){
System.out.println("青蛙" + mammal + "肉食动物");
}
void setMood(int newValue){
mood = newValue;
}
void getMood(){
if(mood == 1)
System.out.println("青蛙高兴时会游泳...");
else
System.out.println("青蛙不高兴时会潜水...");
}
void sayHello(){
System.out.println("青蛙跟人打招呼是呱呱叫...");
}
public void getNumberOfLegs(){
System.out.println("青蛙有" + legs + "条腿");
}
public void hasGills(){
System.out.println("青蛙有鳃");
}
public void laysEggs(){
System.out.println("青蛙是卵生的");
}
void showInfo(){
System.out.println("-- * -- * -- * -- * -- * -- * -- * -- * --");
isMammal();
isCarnivorous();
getNumberOfLegs();
getMood();
hasGills();
laysEggs();
sayHello();
System.out.println("-- * -- * -- * -- * -- * -- * -- * -- * --");
}
}
class Bird extends Animal implements LandAnimal{
private int legs;
Bird(){
super(false,false);
legs = 2;
}
void isMammal(){
System.out.println("鸟" + mammal + "哺乳动物");
}
void isCarnivorous(){
System.out.println("鸟" + mammal + "肉食动物");
}
void setMood(int newValue){
mood = newValue;
}
void getMood(){
if(mood == 1)
System.out.println("鸟高兴时会飞天...");
else
System.out.println("鸟不高兴时下地...");
}
void sayHello(){
System.out.println("鸟跟人打招呼是唱歌...");
}
public void getNumberOfLegs(){
System.out.println("鸟有" + legs + "条腿");
}
void showInfo(){
System.out.println("-- * -- * -- * -- * -- * -- * -- * -- * --");
isMammal();
isCarnivorous();
getNumberOfLegs();
getMood();
sayHello();
System.out.println("-- * -- * -- * -- * -- * -- * -- * -- * --");
}
}
class Test{
public static void main(String args[]){
Dog d = new Dog();
d.setMood(1);
d.showInfo();
Cat c = new Cat();
c.setMood(1);
c.showInfo();
Frog f = new Frog();
f.setMood(1);
f.showInfo();
Bird b = new Bird();
b.setMood(2);
b.showInfo();
}
}