各位大神 帮我敲个java程序吧 (要求看图片 满意了 还加分) 急啊 发到812 4 23 07 4
import?java.util.Scanner;
public?class?Student?{
private?String?stuname?=?"";
private?float?stuscore?=?0;
public?String?getStuname()?{
return?stuname;
}
public?void?setStuname(String?stuname)?{
this.stuname?=?stuname;
}
public?float?getStuscore()?{
return?stuscore;
}
public?void?setStuscore(float?stuscore)?{
this.stuscore?=?stuscore;
}
public?Boolean?compare(Student?st1,?Student?st2)?{
return?st1.stuscore?<?st2.stuscore;
}
/**
?*?@param?args
?*/
public?static?void?main(String[]?args)?{
Student[]?stu?=?new?Student[20];
Scanner?scan?=?new?Scanner(System.in);
int?nCount?=?0;
System.out.println("请输入输入的学生个数:");
nCount?=?scan.nextInt();
System.out.println("请输入输入的学生姓名和分数:");
int?nCurrent?=?0;
while?(nCurrent?<?nCount)?{
Scanner?sca?=?new?Scanner(System.in);
String?strLine?=?sca.nextLine();
String[]?strLineArr?=?strLine.split("?");
Student?st?=?new?Student();
st.setStuname(strLineArr[0]);
st.setStuscore(Float.parseFloat(strLineArr[1]));
stu[nCurrent]?=?st;
nCurrent++;
}
//?排序
for?(int?i?=?0;?i?<?nCount;?i++)?{
for?(int?j?=?0;?j?<?nCount?-?i?-?1;?j++)?{
if?(stu[j].getStuscore()?>?stu[j?+?1].getStuscore())?{
Student?tmp?=?new?Student();
tmp.setStuname(stu[j].getStuname());
tmp.setStuscore(stu[j].getStuscore());
stu[j].setStuname(stu[j?+?1].getStuname());
stu[j].setStuscore(stu[j?+?1].getStuscore());
stu[j?+?1].setStuname(tmp.getStuname());
stu[j?+?1].setStuscore(tmp.getStuscore());
}
}
}
float?avescore?=?0;
float?sum?=?0;
for?(int?i?=?0;?i?<?nCount;?i++)?{
sum?+=?stu[i].getStuscore();
}
avescore?=?sum?/?nCount;
System.out.println("最低分数:"?+?stu[0].getStuname()?+?"?"
+?stu[0].getStuscore());
System.out.println("最高分数:"?+?stu[nCount?-?1].getStuname()?+?"?"
+?stu[nCount?-?1].getStuscore());
System.out.println("平均分数:"?+?avescore);
System.out.println("排序后的数据如下:");
for?(int?i?=?0;?i?<?nCount;?i++)?{
System.out
.println(stu[i].getStuname()?+?"?"?+?stu[i].getStuscore());
}
}
}
结果如下: