java创建学生类,包含学号,姓名,成绩等成员变量及其对应方法

java创建学生类,包含学号,姓名,成绩等成员变量及其对应方法,通过键盘输入若干个学生的信息,直到输入#号后结束输入,按成绩从低到高输出学生对象信息... java创建学生类,包含学号,姓名,成绩等成员变量及其对应方法,通过键盘输入若干个学生的信息,直到输入#号后结束输入,按成绩从低到高输出学生对象信息 展开
 我来答
旅春冬TJ
2015-06-24 · TA获得超过1082个赞
知道大有可为答主
回答量:1271
采纳率:66%
帮助的人:471万
展开全部
package com.baidu;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Student {
private String id;
private String name;
private float score;

public Student(){
this("", "", 0.0f);
}

public Student(String id, String name, float score){
this.id = id;
this.name = name;
this.score = score;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public float getScore() {
return score;
}

public void setScore(float score) {
this.score = score;
}


@Override
public String toString() {
return "Student [id=" + id + ", name=" + name + ", score=" + score
+ "]";
}

public static void main(String[] args) {
List<Student> student = new ArrayList<Student>();
Scanner in = new Scanner(System.in);
System.out.println("Please input the id name and score");
System.out.println("if you want to end of input just input #");
String temp = in.nextLine();
while (!temp.equals("#")){
Student stu = new Student();
stu.setId(temp);
stu.setName(in.nextLine());
stu.setScore(Float.valueOf(in.nextLine()));
student.add(stu);
temp = in.nextLine();
}
Collections.sort(student, new Comparator<Student>(){
@Override
public int compare(Student o1, Student o2) {
if (o1.getScore() > o2.getScore()){
return 1;
} else if(o1.getScore() < o2.getScore()){
return -1;
} else {
return 0;
}
}

});

for (Student a : student){
System.out.println(a);
}

if (null != in){
in.close();
}
}

}
说好的幸福呢納
2015-06-24
知道答主
回答量:8
采纳率:0%
帮助的人:4.7万
展开全部
楼主难点在哪里?
追问
难点在于我是入门的,不会
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式