题目:
使用java面向对象创建动物类并输出动物信息
gitup下载地址:
https://github.com/benxiaohai8888/Javase/blob/master/Animal.java
代码:
import java.util.Scanner;
public class Animal{
private double weight;//体重
private int leg;//腿的数量
private String color;//颜色
private Animal[] animals;//声明一个数组,用来存储几个动物
public void setWeight(double weight){
this.weight=weight;
}
public double getWeight(){
return weight;
}
public void setLeg(int leg){
this.leg=leg;
}
public int getLeg(){
return leg;
}
public void setColor(String color){
this.color=color;
}
public String getColor(){
return color;
}
//初始化动物
public void initAnimal(){
Scanner scanner=new Scanner(System.in);
System.out.println("-----------------请输入动物的信息--------------------");
animals=new Animal[3];
int j=1;
for(int i=0;i
结果: