一个关于狗记录的Java练习

package 狗场;
import java.util.*;
public class dogRoom {

/**
* 作者.范铭祥
* 狗场的狗体重查询问题
*/

public static void main(String[] args)
{
float allweight=0;
dog xx[]=new dog[4];
for(int i=0;i<4;i++)
{
xx[i]=new dog();
}
xx[0].name="花花";
xx[0].weight=4.5f;
xx[1].name="白白";
xx[1].weight=5.6f;
xx[2].name="黑黑";
xx[2].weight=7.8f;
xx[3].name="红红";
xx[3].weight=9.0f;
for(int i=0;i<4;i++)
{
System.out.println(xx[i].name+xx[i].weight+"\n");
allweight=allweight+xx[i].weight;
}
System.out.println("四只狗的总体重为"+allweight);
System.out.println("四只狗的平均体重为"+allweight/4);
//查找狗的系统
boolean Y=true;
Scanner in=new Scanner(System.in);

do
{
System.out.println("请输入你要查询的狗名:");
String name=in.next();
chaxun no1=new chaxun();
no1.chaxun1(name,xx);

}while(Y);
}

}
class dog
{
public String name;
public float weight;
}
class chaxun
{
String cc;
public void chaxun1(String name, dog[] xx) {
// TODO Auto-generated method stub
this.cc=name;
if(cc.equals("花花"))
{
System.out.println(xx[0].weight+"\n");
}
if(cc.equals("白白"))
{
System.out.println(xx[1].weight+"\n");
}
if(cc.equals("黑黑"))
{
System.out.println(xx[2].weight+"\n");
}
if(cc.equals("红红"))
{
System.out.println(xx[3].weight+"\n");
}

}


}

你可能感兴趣的:(java)