简单的Java程序,实现学生的数学,语文成绩的录入排序和查询。

不用数据库,用几个比如学生类,排序类,查询类实现学生的数学,语文成绩的录入排序和查询。输入类似这种stu.add(newStudent("张1",95.0f,90.0f)... 不用数据库,用几个比如学生类,排序类,查询类实现学生的数学,语文成绩的录入排序和查询。输入类似这种
stu.add(new Student("张1",95.0f,90.0f)) ;
stu.add(new Student("张2",94.0f,70.0f)) ;
stu.add(new Student("张3",93.0f,54.0f)) ;
stu.add(new Student("张4",92.0f,78.0f)) ;
stu.add(new Student("张5",91.0f,90.0f)) ;
求大神帮我编个程序
展开
 我来答
百度网友a796c4d
推荐于2016-05-10 · TA获得超过298个赞
知道小有建树答主
回答量:317
采纳率:33%
帮助的人:168万
展开全部

我刚写的,可能还有点漏洞

import java.util.*;
import java.util.Scanner;
public class Bd05 {

public static final Scanner s = new Scanner(System.in);

public static void main(String[] args) {
ArrayList<Student> al = new ArrayList<Student>();
home(al);
}

public static void home(List<Student> list){
while(true){
System.out.println("1.录入学生信息     2.查询学生信息     3.删除学生信息     4.退出\n输入数字选择:");
int num = s.nextInt();
switch(num){
case 1:
inputInfo(list);
break;
case 2:
findInfo(list);
break;
case 3:
remove(list);
break;
case 4:
System.exit(0);
}
}
}
public static void findInfo(List<Student> list){ //查询信息
System.out.println("1.升序     2.降序      3.返回\n输入数字选择查询方式(两科的总分):");
int num = 0;
while(true){
num = s.nextInt();
if(num==1){ //升序
Collections.sort(list,new Comparator<Student>(){
public int compare(Student s1, Student s2) {
int n = new Integer(s1.getChinese()+s1.getMath()).compareTo(new Integer(s2.getChinese()+s2.getMath()));
if(n==0)
return s1.getName().compareTo(s2.getName());
return n;
}
});
printAll(list);
}
else if(num==2){ //降序
Collections.sort(list,new Comparator<Student>(){
public int compare(Student s1, Student s2) {
int n = new Integer(s2.getChinese()+s2.getMath()).compareTo(new Integer(s1.getChinese()+s1.getMath()));
if(n==0)
return s2.getName().compareTo(s1.getName());
return n;
}
});
printAll(list);
}
else if(num==3)
break;
else
System.out.println("输入错误,重新输入:");
}
home(list);
}
public static void remove(List<Student> list){ //删除信息
System.out.print("输入需要删除的姓名:");
String name = s.next();
Iterator<Student> it = list.listIterator();
while(it.hasNext()){
Student str = it.next();
if(name.equals(str.getName())){
it.remove();
System.out.println(name+" 删除成功!");
}
}
System.out.println("1.继续     2.返回\n输入数字选择:");
while(true){
int num = s.nextInt();
if(num==1){
remove(list);
}
else if(num==2)
break;
else
System.out.println("输入错误,重新输入:");
}
home(list);
}
public static void printAll(List<Student> list){
int num = 1;
System.out.println("--------------(查询)----------------");
for(Student stu:list){
System.out.println(num++ +".姓名:"+stu.getName()+"|语文成绩:"+stu.getChinese()+"|数学成绩:"+stu.getMath()+"---|总分:"+(stu.getChinese()+stu.getMath()));
}
System.out.println("-----------------------------------");
home(list);
}
public static void inputInfo(List<Student> list){ //输入信息
System.out.println("输入学生姓名:");
String name = s.next();
System.out.println("输入数学成绩:");
int Math = s.nextInt();
System.out.println("输入语文成绩:");
int chinese = s.nextInt();
list.add(new Student(name,Math,chinese));
System.out.println("1.返回     2.继续录入\n输入数字选择:");
while(true){
int num = s.nextInt();
if(num==1)
break;
else if(num==2)
inputInfo(list);
else
System.out.println("输入错误,重新输入:");
}
home(list);
}
}
class Student{
private String name;
private int chinese;
private int math;
Student(String name,int math,int chinese){
this.name = name;
this.chinese = chinese;
this.math = math;
}
public String  getName(){
return name;
}
public int getChinese(){
return chinese;
}
public int getMath(){
return math;
}
}
匿名用户
2015-10-15
展开全部
那就使用List<Student>

输入完,就统计一下
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式