📄 dog.java
字号:
public class Dog extends Animal implements LandAnimal{
int NumberOfLegs;
public Dog(boolean mammal,boolean carnivorous,int NumberOfLegs){
super(mammal,carnivorous);
this.NumberOfLegs=NumberOfLegs;
}
public void sayHello(){
System.out.println("狗通常情况下,和个打招呼的方式为:摇摇尾巴");
}
public void sayHello(int newValue){
if(newValue==1){
System.out.println("狗被抚摸情绪好的时候,打招呼的方式是:旺旺旺叫");
}else if(newValue==2){
System.out.println("狗烦躁的时候会:呜呜叫");
}
}
public int getNumberOfLegs(){
return NumberOfLegs;
}
}
class Cat extends Animal implements LandAnimal{
int NumberOfLegs;
public Cat(boolean mammal,boolean carnivorous,int NumberOfLegs){
super(mammal,carnivorous);
this.NumberOfLegs=NumberOfLegs;
}
public void sayHello(){
System.out.println("猫通常情况下,和个打招呼的方式为:喵喵叫");
}
public void sayHello(int newValue){
if(newValue==1){
System.out.println("猫情绪好的时候会:咕噜咕噜叫");
}else if(newValue==2){
System.out.println("猫烦躁的时候会:呜呜叫");
}
}
public int getNumberOfLegs(){
return NumberOfLegs;
}
}
class Frog extends Animal implements LandAnimal,WaterAnimal{
int NumberOfLegs;
boolean luan;
boolean sai;
public Frog(boolean mammal,boolean carnivorous,int NumberOfLegs,boolean luan,boolean sai){
super(mammal,carnivorous);
this.NumberOfLegs=NumberOfLegs;
this.luan=luan;
this.sai=sai;
}
public void sayHello(){
System.out.println("青蛙通常情况下,和个打招呼的方式为:呱呱呱");
}
public void sayHello(int newValue){
if(newValue==1){
System.out.println("青蛙情绪好的时候会:呱呱呱");
}else if(newValue==2){
System.out.println("青蛙受到惊吓时会:扑通一声跳下水");
}
}
public int getNumberOfLegs(){
return NumberOfLegs;
}
public boolean hasGills(){
return luan;
}
public boolean laysEggs(){
return sai;
}
}
class test{
public static void main(String[] args){
Dog d=new Dog(true,true,4);
if(d.ismammal()==true){
System.out.println("狗是哺乳动物");
}else{
System.out.println("狗不是哺乳动物");
}
if(d.iscarnivorous()==true){
System.out.println("狗是肉食动物");
}else{
System.out.println("狗不是肉食动物");
}
d.sayHello();
d.setMood(1);
d.sayHello(d.getMood());
d.setMood(2);
d.sayHello(d.getMood());
System.out.println("狗有"+d.getNumberOfLegs()+"条腿");
System.out.println();
Cat c=new Cat(true,true,4);
if(c.ismammal()==true){
System.out.println("猫是哺乳动物");
}else{
System.out.println("猫不是哺乳动物");
}
if(c.iscarnivorous()==true){
System.out.println("猫是肉食动物");
}else{
System.out.println("猫不是肉食动物");
}
c.sayHello();
c.setMood(1);
c.sayHello(c.getMood());
c.setMood(2);
c.sayHello(c.getMood());
System.out.println("猫有"+c.getNumberOfLegs()+"条腿");
System.out.println();
Frog f=new Frog(false,false,4,true,true);
if(f.ismammal()==true){
System.out.println("青蛙是哺乳动物");
}else{
System.out.println("青蛙不是哺乳动物");
}
if(f.iscarnivorous()==true){
System.out.println("青蛙是肉食动物");
}else{
System.out.println("青蛙不是肉食动物");
}
f.sayHello();
f.setMood(1);
f.sayHello(f.getMood());
f.setMood(2);
f.sayHello(f.getMood());
if(f.hasGills()==true){
System.out.println("青蛙产卵");
}else{
System.out.println("青蛙不产卵");
}
if(f.laysEggs()==true){
System.out.println("青蛙有鳃");
}else{
System.out.println("青蛙没有鳃");
}
System.out.println("青蛙有"+f.getNumberOfLegs()+"条腿");
System.out.println();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -