急急急,求考试java编程代码。

高分请讲解下,急急急,求考试java编程代码。
最新回答
扯蛋的青春

2024-07-09 12:58:02

public class Animal
{
// 动物名称 颜色 类别

private String name;

public String getName()
{
return name;
}

public void setName(String name)
{
this.name = name;
}

private String color;

public String getColor()
{
return color;
}
private String type;

public String getType()
{
return type;
}

public void setType(String type)
{
this.type= type;
}

private String amlClass;

public String getAmlClass()
{
return amlClass;
}

public void setAmlClass(String amlClass)
{
this.amlClass = amlClass;
}

public String shout()
{
if (this.name.equals("兔子"))
{
return "叽叽叽";
}
else if (this.name.equals("青蛙"))
{
return "呱呱呱";
}
return ""; }

public String eat()
{
if (this.name.equals("兔子"))
{
return "胡萝卜";
}
else if (this.name.equals("青蛙"))
{
return "昆虫";
}
return ""; }

}

public interface SwimmingInter
{
String swimming();

}

public class Rabbit extends Animal
{
public Rabbit()
{
this.setName("美人");
this.setColor("黑色");
this.setAmlClass("哺乳类");
this.setType("兔子");

}
}

public class Frog extends Animal implements SwimmingInter

{
public Frog()
{
this.setName("大兵");
this.setColor("绿色");
this.setAmlClass("非哺乳类");
this.setType("青蛙");

}

public String swimming()
{
return "虽然不是鱼,但青蛙也是游泳高手";

}

}

main 函数
Frog frog = new Frog();
Rabbit rabbit = new Rabbit();

System.out.println("那只"+frog.getColor+",名叫"+forg.getName()+的+frog.getType());
// 这部分输出 就省略了 拼一下就好! 大部分手敲 所以直接拷过去可能有格式问题不能直接用! 照着敲一遍 应该就ok! 我小菜来的~ 不要分了~ 写错不要喷~
萌面人

2024-07-09 19:30:37

王牌冤家

2024-07-09 14:31:00

public class Animal {
String name = "";
String color = "";
String kind[] = {"buru","fburu"};
public void cry(String names,String colors,String kinds[]){
this.name = names;
this.color = colors;
this.kind = kinds;
System.out.println("那只"+colors+"的,名叫"+names+"正在叫");
}
public void eat(){
}
}
public interface Swim(){
public void swim(){
System.out.println("");
};
};
public class Rabit extends Animal(){
Animal a = new Rabit();
a.cry("美人的兔子","黑色",kind[0]);
}
public class Frog extends Animal implements Swim()
{
Animal b = new Frog();
b.cry("大兵的青蛙","绿色","kind[1]");
b.swim()
{
System.out.println("虽然不是鱼,但青蛙也是游坛高手");
}
}
追问
有截图吗
追答