学生成绩管理系统

来源:互联网 发布:可以货到付款的软件 编辑:程序博客网 时间:2024/05/02 04:40
/** * 作者: * 日期:2013-11-20 * 功能:实现 简单学生成绩管理系统 * 1.定义一个书租用,用户输入10个同学的成绩,数组下标即代表学生学号 * 2.输入学号,打印学生成绩 * 3.输入成绩,打印学号 * 4.统计各个阶段学生人数(优良中差) * 5.输入学号,实现删除学生成绩功能 */package com.se;import java.util.*;public class Demo1 {public static void main(String[] args) {ManageStu ms = null;Scanner in = new Scanner(System.in);while(true){System.out.println("1.录入成绩");System.out.println("2.输入学号,打印学生成绩");System.out.println("3.输入成绩,打印学号");System.out.println("4.统计各个阶段学生人数");System.out.println("5.输入学号,实现删除学生成绩功能");System.out.println("6.退出");int n = in.nextInt();if(n==1){ms = new ManageStu();}else if(n==2){System.out.println("请输入要查询的学号:");int no = in.nextInt();ms.getScore(no);}else if(n==3){System.out.println("请输入要查询的成绩:");float scor = in.nextFloat();ms.getNo(scor);}else if(n==4){ms.getDifferent();}else if(n==5){System.out.println("请输入要删除的学号:");int no = in.nextInt();ms.delStu(no);}else if(n==6){System.exit(0);}}}}//操作学生的类class ManageStu{Scanner in = new Scanner(System.in);//1.定义一个书租用,用户输入10个同学的成绩,数组下标即代表学生学号float score[] = null;int num = 5;public ManageStu(){score = new float[num];for(int i=0;i<num;i++){System.out.println("请输入第"+(i+1)+"位学生成绩");score[i] = in.nextFloat();}}//2.输入学号,打印学生成绩public void getScore(int no){try {System.out.println(score[no]);} catch (Exception e) {System.out.println("输入的学号有误!");}}//3.输入成绩,打印学号public void getNo(float scor){int k = 0;for(int i=0;i<num;i++){if(score[i] == scor){System.out.println("学号:"+i);k++;}}if(k==0){System.out.println("该成绩没有对应的学生!");}}//4.统计各个阶段学生人数(优良中差)public void getDifferent(){int a = 0;int b = 0;int c = 0;int d = 0;for(int i=0;i<num;i++){if(score[i]<60&&score[i]>0) d++;else if(score[i]>=60&&score[i]<80) c++;else if(score[i]>=80&&score[i]<90) b++;else if(score[i]>=90&&score[i]<=100) a++;}System.out.println("优:"+a+"  良:"+b+"  中:"+c+"  差"+d);}//5.输入学号,实现删除学生成绩功能public void delStu(int no){try {score[no] = 0;System.out.println("删除成功!");} catch (Exception e) {System.out.println("输入的学号不存在,删除失败!");}}}

原创粉丝点击