[求助]各位高手帮一下忙!
以下是我们老师要我们做的题目呀,可是我做了二天了呀,还是无法达到那种效果,请各位高手帮个忙,写个程序给我吧! 1、以下为某班学生考试成绩表。编写程序(exp3_7.java),要求按总分从大到小输出学生的姓名、总分、名次。
姓名 学号 政治 语文 数学 计算机 体育
李明 1 81 89 99 98 87
张力 2 89 90 95 80 90
王英 3 91 77 88 95 78
赵锐 4 79 84 95 93 96
周密 5 95 92 98 99 93
吴川 6 78 88 85 86 80
孙康 7 91 85 94 82 88
郑重 8 90 92 94 90 95
胡琴 9 75 85 87 94 90 因为对JAVA里面的很多东西不懂所以请说清楚一点谢谢了!
----------------解决方案--------------------------------------------------------
看一下数组那一章节再试试
----------------解决方案--------------------------------------------------------
写了一个,我也是刚学,可能效率不是很高,但是,结果正确!
import java.lang.*;
class Student
{
String xm;
int xh;
float[] score;
float zongfen;
Student(String name,int num,float zhz,float yw,float sx,float com,float ty)
{
int i;
score=new float[5];
this.score[0]=zhz;
this.score[1]=yw;
this.score[2]=sx;
this.score[3]=com;
this.score[4]=ty;
this.zongfen=0;
for(i=0;i<=4;i++)
this.zongfen=this.zongfen+this.score[i];
this.xm=name;
this.xh=num;
}
Student(Student a)
{
int i;
this.xm=a.xm;
this.xh=a.xh;
score=new float[5];
this.score[0]=a.score[0];
this.score[1]=a.score[1];
this.score[2]=a.score[2];
this.score[3]=a.score[3];
this.score[4]=a.score[4];
this.zongfen=0;
for(i=0;i<=4;i++)
this.zongfen=this.zongfen+this.score[i];
}
}
public class Sort
{
void paixu(Student[] stu)
{
int i,j,k;
i=stu.length;
for(k=1;k<=i;k++)
for(j=0;j<=i-2;j++)
{
if(stu[j].zongfen<stu[j+1].zongfen)
{
Student temp=new Student(stu[j]);
stu[j]=stu[j+1];
stu[j+1]=temp;
}
}
for(k=0;k<=i-1;k++)
System.out.println(stu[k].xm+"\t"+stu[k].xh+"\t"+stu[k].zongfen);
}
public static void main(String[] args)
{
Student[] starray=new Student[9];
Sort st=new Sort();
starray[0]=new Student("黎明",1,81,89,99,98,87);
starray[1]=new Student("张力",2,89,90,95,80,90);
starray[2]=new Student("王英",3,91,77,88,95,78);
starray[3]=new Student("赵锐",4,79,84,95,93,96);
starray[4]=new Student("周密",5,95,92,98,99,93);
starray[5]=new Student("周川",6,78,88,85,86,80);
starray[6]=new Student("孙康",7,91,85,94,82,88);
starray[7]=new Student("郑重",8,90,92,94,90,95);
starray[8]=new Student("胡琴",9,75,85,87,94,90);
st.paixu(starray);
}
}
----------------解决方案--------------------------------------------------------
加了注释的程序: import java.lang.*; //定义一个学生类 class Student { String xm; /*姓名*/ int xh; /*学号*/ float[] score; /*分数数组*/ float zongfen; /*总分*/ Student(String name,int num,float zhz,float yw,float sx,float com,float ty) /*构造函数*/ { int i; score=new float[5]; /*数组实例化*/ this.score[0]=zhz; this.score[1]=yw; this.score[2]=sx; this.score[3]=com; this.score[4]=ty; this.zongfen=0; for(i=0;i<=4;i++) this.zongfen=this.zongfen+this.score[i]; /*计算总分*/ this.xm=name; this.xh=num; } Student(Student a) /*构造函数*/ { int i; this.xm=a.xm; this.xh=a.xh; score=new float[5]; this.score[0]=a.score[0]; this.score[1]=a.score[1]; this.score[2]=a.score[2]; this.score[3]=a.score[3]; this.score[4]=a.score[4]; this.zongfen=0; for(i=0;i<=4;i++) this.zongfen=this.zongfen+this.score[i]; } } public class Sort { void paixu(Student[] stu) { int i,j,k; i=stu.length; /*确定数组长度*/ /*以下为排序部分*/ for(k=1;k<=i;k++) for(j=0;j<=i-2;j++) { if(stu[j].zongfen<stu[j+1].zongfen) { Student temp=new Student(stu[j]); stu[j]=stu[j+1]; stu[j+1]=temp; } } for(k=0;k<=i-1;k++) System.out.println(stu[k].xm+"\t"+stu[k].xh+"\t"+stu[k].zongfen); } public static void main(String[] args) { Student[] starray=new Student[9]; Sort st=new Sort(); /*实例化各个数组元素*/ starray[0]=new Student("黎明",1,81,89,99,98,87); starray[1]=new Student("张力",2,89,90,95,80,90); starray[2]=new Student("王英",3,91,77,88,95,78); starray[3]=new Student("赵锐",4,79,84,95,93,96); starray[4]=new Student("周密",5,95,92,98,99,93); starray[5]=new Student("周川",6,78,88,85,86,80); starray[6]=new Student("孙康",7,91,85,94,82,88); starray[7]=new Student("郑重",8,90,92,94,90,95); starray[8]=new Student("胡琴",9,75,85,87,94,90); st.paixu(starray); /*调用排序方法*/ } } 名次自己加吧!
----------------解决方案--------------------------------------------------------
呵呵,楼上的加油,不错
----------------解决方案--------------------------------------------------------
哦哦,
谢谢楼上的俩位哥,
谢谢你们了,哈哈,我会好好向你们俩学习的呀!
----------------解决方案--------------------------------------------------------