public class Demo4{
piblic static void main(String [] args){
//定义一个可以存放四只狗的对象数组
Dog dogs[]=new Dog[4];
//给各个狗赋初值
dogs[0]=new Dog;
dogs[0].setName("花花");
dogs[0].setWeight(4.5f);
}
//控制台输入各个狗的信息
Scanner scan=new Scanner(System.in);
double input=scan.nextDouble();
for(int i=0;i<4;i++){
dogs[i]=new Dog();
System.out.println("请输入狗名");
//从控制台输入狗名
String name=scan.nextLine();
//将名字赋给对象
dogs[i].setName(name);
//从控制台输入狗的体重
System.out.println("请输入狗的体重");
double weight=scan.nextDouble();
dogs[i].setWeight(weight);
}
//计算平均体重
//先计算总体重
}
//定义一个狗类
class Dog{
private float weight;
private String name;
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
public float getWeight(){
return weight;
}
public void setWeight(float weight){
this.weight=weight;
}
}