【菜鸟求助】学生成绩管理系统排序问题

橙子好酸 2017-06-03 10:53:23
期末作业要做一个学生成绩管理系统,就差一个成绩排序功能了,没有思路,请各位大佬指点一下
部分代码如下:

package CPMS;
public class student{
String name;
double score ;

//获得学生姓名
public String getName() {
return name;
}

//设置学生姓名
public void setName(String zcName) {
name = zcName;
}

//获得学生成绩分数
public double getScore() {
return score;
}

//设置学生成绩分数
public void setScore(double zcScore) {
score = zcScore;
}

//定义一个无参的构造方法
public student () {

}

//定义一个带参的构造方法
public student(String name)
{
this.name = name;
this.score = 0;
}


//定义一个带参数的构造方法
public student (String name,double score) {
this.name = name;
this.score = score;
}

//输出学生的姓名和成绩
public String toString () {
return "学生姓名:"+name+",成绩:"+score;
}
}





package CPMS;
import CPMS.student;
import java.util.Scanner;
import java.io.Serializable;

public class banJi implements Serializable {
student [] array;//保存学生的数组
int number;//学生数量


public banJi() {
array = new student [100];
number = 0;
}


public banJi (int number) {
String name;
double score;
Scanner sc = new Scanner(System.in);

this.array = new student [100];
this.number = number;

for (int i = 0;i<number;i++) {
System.out.println("输入第"+(i+1)+"位同学:");
System.out.println("姓名:");
name = sc.next();
System.out.println("成绩");
score = sc.nextDouble();

this.array [i] = new student (name,score);
}
}



/*获取人数*/
public boolean student(int number)
{
if(this.number == this.array.length)
{
System.out.println("空间存满,不能添加");
return false;
}
else
{
number ++;
return true;
}
}

/*查找方法*/
public student search(String name)
{
for(int j = 0;j < this.number;j++)
{
if(name.compareTo(this.array[j].getName())==0)
return this.array[j];
}
return null;
}

/*浏览方法*/
public void display()
{
System.out.println("--通讯录--");
System.out.println("姓名 电话");
for(int i=0;i < number;i++)
{
System.out.println(this.array[i].toString());
}
System.out.println("结束");
}

/*添加联系人*/
public String append(String name,double score)
{
array[this.number]=new student();
array[this.number].name = name;
array[this.number].score = score;
this.number++;
return "添加成功";
}

/*求平均分*/
public void average () {
double a=0;
double total = 0;
for (int k=0;k<number;k++) {
total += array[k].score;
}
a = total/number;
System.out.println("平均分为:"+a);
}


/*最高分学生*/
public void maxStu () {
int s=0;
double max = this.array[0].score;
for (int l=0;l<this.number;l++) {
if (array[l].score > max)
max =this.array[l].score;
s=l;
}
System.out.println("最高分学生是:"+this.array[s-1].name+",分数为"+max);
}


/*成绩由高到低排序*/
public void scoreSort () {

}




/*获取student类型的数组内容*/
public student getStudent(int i)
{
if(i>=0&&i<this.number)
return this.array[i];
return null;
}

}
...全文
278 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
橙子好酸 2017-06-04
  • 打赏
  • 举报
回复 1
完美,多谢老哥
李德胜1995 2017-06-03
  • 打赏
  • 举报
回复 2
随便写个排序就行了。。。。

 public void scoreSort () {
    	for (int i = 0; i <number-1; i++) {
			for (int j = 0; j <number-i-1; j++) {
				if(array[j].getScore()>array[j+1].getScore()){
					student temp=array[j];
					array[j]=array[j+1];
					array[j+1]=temp;
				}
			}
		}
    	for (int i =number-1; i>=0; i--) {
			System.out.println(array[i].getName()+"的得分是:"+array[i].getScore());
		}
    }

51,412

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧