摆脱前辈们帮我看一下,编的显示动物信息的代码 改了几次运行不了 真查不出什么出问题了 麻烦前辈帮我检查下错误 能编译就好了 分不多 请前辈们包涵
import java.util.*;
abstract class Animal
{
boolean mammal; //哺乳动物
boolean carnivorous; //肉食性
int mood; //心情
abstract void isMammal();
abstract void isCarnivorous();
abstract void setMood(int newValue);
abstract void getMood();
abstract void sayHello();
}interface LandAnimal
{
public int getNumberOflegs();
}
interface WaterAnimal
{
public void hasGills();
public void laysEggs();
}
class Dog extends Animal implements LandAnimal
{
Dog()
{
mammal=true;
carnivorous=true;
}
void isMammal()
{
if(mammal==true)
{
System.out.println("狗是哺乳动物");
}
else
{
System.out.println("狗不是哺乳动物");
}
}
void isCarnivorous()
{
if(carnivorous==true)
{
System.out.println("狗是肉食动物");
}
else
{
System.out.println("狗不是肉食动物");
}
}
void getMood()
{
do{ System.out.println("请设置情绪:(1-4为烦躁 5 为通常 6-10为情绪好");
Scanner ani = ani.Scanner(System.in);
mood=ani.nextInt();
if(mood>10 && mood<1)
{
System.out.println("请输入有误,请重新输入:");
}
setMood(mood);
}while(mood>10 && mood<1);
}
void setMood(int newValue)
{
mood=newValue;
}
void sayHello()
{
if(mood>=1 && mood<=4)
{
System.out.println("狗烦躁的时候会:呜呜叫");
}
else if(mood==5)
{
System.out.println("狗在通常情况下,和人打招呼的方式为:摇摇尾巴");
}
else if(mood>=6 && mood<=10)
{
System.out.println("狗被抚摸情绪好的时候,打招呼的方式是:汪汪汪叫");
}
}
public int getNumberOflegs()
{
return 4;
}
}
class Cat extends Animal implements LandAnimal
{
Cat()
{
mammal=true;
carnivorous=true;
}
void isMammal()
{
if(mammal==true)
{
System.out.println("猫是哺乳动物");
}
else
{
System.out.println("猫不是哺乳动物");
}
}
void isCarnivorous()
{
if(carnivorous==true)
{
System.out.println("猫是肉食动物");
}
else
{
System.out.println("猫不是肉食动物");
}
}
void getMood()
{
do{ System.out.println("请设置情绪:(1-4为烦躁 5 为通常 6-10为情绪好");
Scanner ani = ani.Scanner(System.in);
mood=ani.nextInt();
if(mood>10 && mood<1)
{
System.out.println("请输入有误,请重新输入:");
}
setMood(mood);
}while(mood>10 && mood<1);
}
void setMood(int newValue)
{
mood=newValue;
}
void sayHello()
{
if(mood>=1 && mood<=4)
{
System.out.println("猫烦躁的时候会:斯斯叫");
}
else if(mood==5)
{
System.out.println("猫在通常情况下,和人打招呼的方式为:苗苗叫");
}
else if(mood>=6 && mood<=10)
{
System.out.println("猫被抚摸情绪好的时候,打招呼的方式是:咕噜咕噜叫");
}
}
public int getNumberOflegs()
{
return 4;
}
}
class Frog extends Animal implements LandAnimal,WaterAnimal
{
Frog()
{
mammal=false;
carnivorous=false;
}
void isMammal()
{
if(mammal==true)
{
System.out.println("青蛙是哺乳动物");
}
else
{
System.out.println("青蛙不是哺乳动物");
}
}
void isCarnivorous()
{
if(carnivorous==true)
{
System.out.println("青蛙是肉食动物");
}
else
{
System.out.println("青蛙不是肉食动物");
}
}
void getMood()
{
do{ System.out.println("请设置情绪:(1-4为烦躁 5 为通常 6-10为情绪好");
Scanner ani = ani.Scanner(System.in);
mood=ani.nextInt();
if(mood>10 && mood<1)
{
System.out.println("请输入有误,请重新输入:");
}
setMood(mood);
}while(mood>10 && mood<1);
}
void setMood(int newValue)
{
mood=newValue;
}
void sayHello()
{
if(mood>=1 && mood<=4)
{
System.out.println("青蛙受到惊吓的时候会:扑通一声跳入水中");
}
else if(mood==5)
{
System.out.println("青蛙在通常情况下,和人打招呼的方式为:呱呱呱");
}
else if(mood>=6 && mood<=10)
{
System.out.println("青蛙被抚摸情绪好的时候会:呱呱叫");
}
}
public void hasGills()
{
System.out.println("青蛙有腮");
}
public void laysEggs()
{
System.out.println("青蛙产卵");
}
public int getNumberOflegs()
{
return 4;
}
}
public class DisplayAnimal
{ public static void main(String []args)
{
do{ System.out.println("请输入一个动物(1:狗 2:猫 3:青蛙 0:退出 ");
Scanner ani = ani.Scanner(System.in);
int num=ani.nextInt();
switch(num)
{
case 0:
exit(0);
case 1:
Dog one =new Dog();
one.isMammal();
one.isCarnivorous();
one.sayHello();
System.out.println("狗有"+one.getNumberOflegs()+"腿");
break;
case 2:
Cat two =new Cat();
two.isMammal();
two.isCarnivorous();
two.sayHello();
System.out.println("猫有"+two.getNumberOflegs()+"腿");
break;
case 3:
Dog three =new Dog();
three.isMammal();
three.isCarnivorous();
three.sayHello();
System.out.println("青蛙有"+three.getNumberOflegs()+"腿");
three.hasGills();
three.laysEggs();
break;
default:
System.out.println("请输入有误,请重新输入");
}
}while(num!=0);
}
}
import java.util.*;
abstract class Animal
{
boolean mammal; //哺乳动物
boolean carnivorous; //肉食性
int mood; //心情
abstract void isMammal();
abstract void isCarnivorous();
abstract void setMood(int newValue);
abstract void getMood();
abstract void sayHello();
}interface LandAnimal
{
public int getNumberOflegs();
}
interface WaterAnimal
{
public void hasGills();
public void laysEggs();
}
class Dog extends Animal implements LandAnimal
{
Dog()
{
mammal=true;
carnivorous=true;
}
void isMammal()
{
if(mammal==true)
{
System.out.println("狗是哺乳动物");
}
else
{
System.out.println("狗不是哺乳动物");
}
}
void isCarnivorous()
{
if(carnivorous==true)
{
System.out.println("狗是肉食动物");
}
else
{
System.out.println("狗不是肉食动物");
}
}
void getMood()
{
do{ System.out.println("请设置情绪:(1-4为烦躁 5 为通常 6-10为情绪好");
Scanner ani = ani.Scanner(System.in);
mood=ani.nextInt();
if(mood>10 && mood<1)
{
System.out.println("请输入有误,请重新输入:");
}
setMood(mood);
}while(mood>10 && mood<1);
}
void setMood(int newValue)
{
mood=newValue;
}
void sayHello()
{
if(mood>=1 && mood<=4)
{
System.out.println("狗烦躁的时候会:呜呜叫");
}
else if(mood==5)
{
System.out.println("狗在通常情况下,和人打招呼的方式为:摇摇尾巴");
}
else if(mood>=6 && mood<=10)
{
System.out.println("狗被抚摸情绪好的时候,打招呼的方式是:汪汪汪叫");
}
}
public int getNumberOflegs()
{
return 4;
}
}
class Cat extends Animal implements LandAnimal
{
Cat()
{
mammal=true;
carnivorous=true;
}
void isMammal()
{
if(mammal==true)
{
System.out.println("猫是哺乳动物");
}
else
{
System.out.println("猫不是哺乳动物");
}
}
void isCarnivorous()
{
if(carnivorous==true)
{
System.out.println("猫是肉食动物");
}
else
{
System.out.println("猫不是肉食动物");
}
}
void getMood()
{
do{ System.out.println("请设置情绪:(1-4为烦躁 5 为通常 6-10为情绪好");
Scanner ani = ani.Scanner(System.in);
mood=ani.nextInt();
if(mood>10 && mood<1)
{
System.out.println("请输入有误,请重新输入:");
}
setMood(mood);
}while(mood>10 && mood<1);
}
void setMood(int newValue)
{
mood=newValue;
}
void sayHello()
{
if(mood>=1 && mood<=4)
{
System.out.println("猫烦躁的时候会:斯斯叫");
}
else if(mood==5)
{
System.out.println("猫在通常情况下,和人打招呼的方式为:苗苗叫");
}
else if(mood>=6 && mood<=10)
{
System.out.println("猫被抚摸情绪好的时候,打招呼的方式是:咕噜咕噜叫");
}
}
public int getNumberOflegs()
{
return 4;
}
}
class Frog extends Animal implements LandAnimal,WaterAnimal
{
Frog()
{
mammal=false;
carnivorous=false;
}
void isMammal()
{
if(mammal==true)
{
System.out.println("青蛙是哺乳动物");
}
else
{
System.out.println("青蛙不是哺乳动物");
}
}
void isCarnivorous()
{
if(carnivorous==true)
{
System.out.println("青蛙是肉食动物");
}
else
{
System.out.println("青蛙不是肉食动物");
}
}
void getMood()
{
do{ System.out.println("请设置情绪:(1-4为烦躁 5 为通常 6-10为情绪好");
Scanner ani = ani.Scanner(System.in);
mood=ani.nextInt();
if(mood>10 && mood<1)
{
System.out.println("请输入有误,请重新输入:");
}
setMood(mood);
}while(mood>10 && mood<1);
}
void setMood(int newValue)
{
mood=newValue;
}
void sayHello()
{
if(mood>=1 && mood<=4)
{
System.out.println("青蛙受到惊吓的时候会:扑通一声跳入水中");
}
else if(mood==5)
{
System.out.println("青蛙在通常情况下,和人打招呼的方式为:呱呱呱");
}
else if(mood>=6 && mood<=10)
{
System.out.println("青蛙被抚摸情绪好的时候会:呱呱叫");
}
}
public void hasGills()
{
System.out.println("青蛙有腮");
}
public void laysEggs()
{
System.out.println("青蛙产卵");
}
public int getNumberOflegs()
{
return 4;
}
}
public class DisplayAnimal
{ public static void main(String []args)
{
do{ System.out.println("请输入一个动物(1:狗 2:猫 3:青蛙 0:退出 ");
Scanner ani = ani.Scanner(System.in);
int num=ani.nextInt();
switch(num)
{
case 0:
exit(0);
case 1:
Dog one =new Dog();
one.isMammal();
one.isCarnivorous();
one.sayHello();
System.out.println("狗有"+one.getNumberOflegs()+"腿");
break;
case 2:
Cat two =new Cat();
two.isMammal();
two.isCarnivorous();
two.sayHello();
System.out.println("猫有"+two.getNumberOflegs()+"腿");
break;
case 3:
Dog three =new Dog();
three.isMammal();
three.isCarnivorous();
three.sayHello();
System.out.println("青蛙有"+three.getNumberOflegs()+"腿");
three.hasGills();
three.laysEggs();
break;
default:
System.out.println("请输入有误,请重新输入");
}
}while(num!=0);
}
}
import java.util.*;abstract class Animal {
boolean mammal; // 哺乳动物 boolean carnivorous; // 肉食性 int mood; // 心情 abstract void isMammal(); abstract void isCarnivorous(); abstract void setMood(int newValue); abstract void getMood(); abstract void sayHello();
}interface LandAnimal {
public int getNumberOflegs();
}interface WaterAnimal {
public void hasGills(); public void laysEggs();
}class Dog extends Animal implements LandAnimal, WaterAnimal { Dog() {
mammal = true;
carnivorous = true;
} void isMammal() {
if (mammal == true) {
System.out.println("狗是哺乳动物");
} else {
System.out.println("狗不是哺乳动物");
}
} void isCarnivorous() {
if (carnivorous == true) {
System.out.println("狗是肉食动物");
} else {
System.out.println("狗不是肉食动物");
}
} void getMood() {
do { System.out.println("请设置情绪:(1-4为烦躁 5 为通常 6-10为情绪好");
Scanner ani = new Scanner(System.in);
mood = ani.nextInt();
if (mood > 10 && mood < 1) {
System.out.println("请输入有误,请重新输入:");
}
setMood(mood);
} while (mood > 10 && mood < 1);
} void setMood(int newValue) {
mood = newValue;
} void sayHello() {
if (mood >= 1 && mood <= 4) {
System.out.println("狗烦躁的时候会:呜呜叫");
} else if (mood == 5) {
System.out.println("狗在通常情况下,和人打招呼的方式为:摇摇尾巴");
} else if (mood >= 6 && mood <= 10) {
System.out.println("狗被抚摸情绪好的时候,打招呼的方式是:汪汪汪叫");
} } public int getNumberOflegs() {
return 4;
} public void hasGills() {
// TODO Auto-generated method stub } public void laysEggs() {
// TODO Auto-generated method stub }
}class Cat extends Animal implements LandAnimal { Cat() {
mammal = true;
carnivorous = true;
} void isMammal() {
if (mammal == true) {
System.out.println("猫是哺乳动物");
} else {
System.out.println("猫不是哺乳动物");
}
} void isCarnivorous() {
if (carnivorous == true) {
System.out.println("猫是肉食动物");
} else {
System.out.println("猫不是肉食动物");
}
} void getMood() {
do { System.out.println("请设置情绪:(1-4为烦躁 5 为通常 6-10为情绪好");
Scanner ani = new Scanner(System.in);
mood = ani.nextInt();
if (mood > 10 && mood < 1) {
System.out.println("请输入有误,请重新输入:");
}
setMood(mood);
} while (mood > 10 && mood < 1);
} void setMood(int newValue) {
mood = newValue;
} void sayHello() {
if (mood >= 1 && mood <= 4) {
System.out.println("猫烦躁的时候会:斯斯叫");
} else if (mood == 5) {
System.out.println("猫在通常情况下,和人打招呼的方式为:苗苗叫");
} else if (mood >= 6 && mood <= 10) {
System.out.println("猫被抚摸情绪好的时候,打招呼的方式是:咕噜咕噜叫");
} } public int getNumberOflegs() {
return 4;
}
}class Frog extends Animal implements LandAnimal, WaterAnimal {
Frog() {
mammal = false;
carnivorous = false;
} void isMammal() {
if (mammal == true) {
System.out.println("青蛙是哺乳动物");
} else {
System.out.println("青蛙不是哺乳动物");
}
} void isCarnivorous() {
if (carnivorous == true) {
System.out.println("青蛙是肉食动物");
} else {
System.out.println("青蛙不是肉食动物");
}
} void getMood() {
do { System.out.println("请设置情绪:(1-4为烦躁 5 为通常 6-10为情绪好");
Scanner ani = new Scanner(System.in);
mood = ani.nextInt();
if (mood > 10 && mood < 1) {
System.out.println("请输入有误,请重新输入:");
}
setMood(mood);
} while (mood > 10 && mood < 1);
} void setMood(int newValue) {
mood = newValue;
} void sayHello() {
if (mood >= 1 && mood <= 4) {
System.out.println("青蛙受到惊吓的时候会:扑通一声跳入水中");
} else if (mood == 5) {
System.out.println("青蛙在通常情况下,和人打招呼的方式为:呱呱呱");
} else if (mood >= 6 && mood <= 10) {
System.out.println("青蛙被抚摸情绪好的时候会:呱呱叫");
} } public void hasGills() {
System.out.println("青蛙有腮");
} public void laysEggs() {
System.out.println("青蛙产卵");
} public int getNumberOflegs() {
return 4;
}
}public class DisplayAnimal { public static void main(String[] args) {
int num;
do { System.out.println("请输入一个动物(1:狗 2:猫 3:青蛙 0:退出 ");
Scanner ani = new Scanner(System.in);
num = ani.nextInt();
switch (num) {
case 0:
System.exit(0);
case 1:
Dog one = new Dog();
one.isMammal();
one.isCarnivorous();
one.sayHello();
System.out.println("狗有" + one.getNumberOflegs() + "腿");
break;
case 2:
Cat two = new Cat();
two.isMammal();
two.isCarnivorous();
two.sayHello();
System.out.println("猫有" + two.getNumberOflegs() + "腿");
break;
case 3:
Dog three = new Dog();
three.isMammal();
three.isCarnivorous();
three.sayHello();
System.out.println("青蛙有" + three.getNumberOflegs() + "腿");
three.hasGills();
three.laysEggs();
break;
default:
System.out.println("请输入有误,请重新输入");
}
} while (num != 0);
}
}
import java.io.*;
abstract class Animal
{
boolean mammal; //哺乳动物
boolean carnivorous; //肉食性
String mood; //心情
abstract void isMammal();
abstract void isCarnivorous();
abstract void setMood(String newValue);
abstract void getMood() throws IOException;
abstract void sayHello();
} interface LandAnimal
{
public int getNumberOflegs();
}
interface WaterAnimal
{
public void hasGills();
public void laysEggs();
}
class Dog extends Animal implements LandAnimal
{
Dog()
{
mammal=true;
carnivorous=true;
}
void isMammal()
{
if(mammal==true)
{
System.out.println("狗是哺乳动物");
}
else
{
System.out.println("狗不是哺乳动物");
}
}
void isCarnivorous()
{
if(carnivorous==true)
{
System.out.println("狗是肉食动物");
}
else
{
System.out.println("狗不是肉食动物");
}
}
void getMood() throws IOException
{
do{ System.out.println("请设置情绪:(1-4为烦躁 5 为通常 6-10为情绪好");
BufferedReader ani = new BufferedReader (new InputStreamReader(System.in));
mood=ani.readLine();
if(Integer.parseInt(mood)> 10 && Integer.parseInt(mood) <1)
{
System.out.println("请输入有误,请重新输入:");
}
setMood(mood);
}while(Integer.parseInt(mood)> 10 && Integer.parseInt(mood) <1);
}
void setMood(String newValue)
{
mood=newValue;
}
void sayHello()
{
if(Integer.parseInt(mood)>=1 && Integer.parseInt(mood) <=4)
{
System.out.println("狗烦躁的时候会:呜呜叫");
}
else if(Integer.parseInt(mood)==5)
{
System.out.println("狗在通常情况下,和人打招呼的方式为:摇摇尾巴");
}
else if(Integer.parseInt(mood)>=6 && Integer.parseInt(mood) <=10)
{
System.out.println("狗被抚摸情绪好的时候,打招呼的方式是:汪汪汪叫");
} }
public int getNumberOflegs()
{
return 4;
}
}
class Cat extends Animal implements LandAnimal
{
Cat()
{
mammal=true;
carnivorous=true;
}
void isMammal()
{
if(mammal==true)
{
System.out.println("猫是哺乳动物");
}
else
{
System.out.println("猫不是哺乳动物");
}
}
void isCarnivorous()
{
if(carnivorous==true)
{
System.out.println("猫是肉食动物");
}
else
{
System.out.println("猫不是肉食动物");
}
}
void getMood() throws IOException
{
do{ System.out.println("请设置情绪:(1-4为烦躁 5 为通常 6-10为情绪好");
BufferedReader ani = new BufferedReader (new InputStreamReader(System.in));
mood=ani.readLine();
if(Integer.parseInt(mood)> 10 && Integer.parseInt(mood) <1)
{
System.out.println("请输入有误,请重新输入:");
}
setMood(mood);
}while(Integer.parseInt(mood)> 10 && Integer.parseInt(mood) <1);
}
void setMood( String newValue)
{
mood=newValue;
}
void sayHello()
{
if(Integer.parseInt(mood)>=1 && Integer.parseInt(mood) <=4)
{
System.out.println("猫烦躁的时候会:斯斯叫");
}
else if(Integer.parseInt(mood)==5)
{
System.out.println("猫在通常情况下,和人打招呼的方式为:苗苗叫");
}
else if(Integer.parseInt(mood)>=6 && Integer.parseInt(mood) <=10)
{
System.out.println("猫被抚摸情绪好的时候,打招呼的方式是:咕噜咕噜叫");
} }
public int getNumberOflegs()
{
return 4;
}
}
class Frog extends Animal implements LandAnimal,WaterAnimal
{
Frog()
{
mammal=false;
carnivorous=false;
}
void isMammal()
{
if(mammal==true)
{
System.out.println("青蛙是哺乳动物");
}
else
{
System.out.println("青蛙不是哺乳动物");
}
}
void isCarnivorous()
{
if(carnivorous==true)
{
System.out.println("青蛙是肉食动物");
}
else
{
System.out.println("青蛙不是肉食动物");
}
}
void getMood() throws IOException
{
do{ System.out.println("请设置情绪:(1-4为烦躁 5 为通常 6-10为情绪好");
BufferedReader ani = new BufferedReader(new InputStreamReader( (System.in)));
mood=ani.readLine();
if(Integer.parseInt(mood)> 10 && Integer.parseInt(mood) <1)
{
System.out.println("请输入有误,请重新输入:");
}
setMood(mood);
}while(Integer.parseInt(mood)> 10 && Integer.parseInt(mood) <1);
}
void setMood(String newValue)
{
mood=String.valueOf(newValue);
}
void sayHello()
{
if(Integer.parseInt(mood)>=1 && Integer.parseInt(mood) <=4)
{
System.out.println("青蛙受到惊吓的时候会:扑通一声跳入水中");
}
else if(Integer.parseInt(mood)==5)
{
System.out.println("青蛙在通常情况下,和人打招呼的方式为:呱呱呱");
}
else if(Integer.parseInt(mood)>=6 && Integer.parseInt(mood) <=10)
{
System.out.println("青蛙被抚摸情绪好的时候会:呱呱叫");
} }
public void hasGills()
{
System.out.println("青蛙有腮");
}
public void laysEggs()
{
System.out.println("青蛙产卵");
}
public int getNumberOflegs()
{
return 4;
}
}
public class TextFile
{ public static void main(String []args) throws IOException
{
String num=null;
do{ System.out.println("请输入一个动物(1:狗 2:猫 3:青蛙 0:退出 ");
BufferedReader ani = new BufferedReader(new InputStreamReader(System.in));
num=ani.readLine();
switch(Integer.parseInt(num))
{
case 0:
break;
case 1:
Dog one =new Dog();
one.isMammal();
one.isCarnivorous();
one.getMood();
one.sayHello();
System.out.println("狗有"+one.getNumberOflegs()+"腿");
break;
case 2:
Cat two =new Cat();
two.isMammal();
two.isCarnivorous();
two.getMood();
two.sayHello();
System.out.println("猫有"+two.getNumberOflegs()+"腿");
break;
case 3:
Dog three =new Dog();
three.isMammal();
three.isCarnivorous();
three.getMood();
three.sayHello();
System.out.println("青蛙有"+three.getNumberOflegs()+"腿"); break;
default:
System.out.println("请输入有误,请重新输入");
}
}while(Integer.parseInt(num)!=0);
}
}