一个学生成绩管理程序

来源:互联网 发布:sql 跨服务器数据同步 编辑:程序博客网 时间:2024/04/27 04:14

实现目的:

1、增加学生对象(学号、姓名、成绩)

2、删除学生对象

3、修改成绩

4、平均成绩

5、分别打出优秀,良、中等、不及格人数的百分比

6、查询学生

 

package studentapplication;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Iterator;

class Studentinfo{

   private  String stunum;
   private  String name;
   private  double score;

   public Studentinfo(String stunum,String name){
       this.stunum = stunum;
       this.name = name;
   }

   public Studentinfo(){

   }

   public String getstunum(){
       return stunum;
   }

   public String getname(){
       return name;
   }

   public double getscore(){
       return score;
   }

   public void setscore(double sc){
       this.score = sc;
   }
}

class Studentinfooper extends Studentinfo{

    HashMap hs = new HashMap();

    public Studentinfooper()
    {

    }

    public Studentinfooper (String s,String n)
    {
        super(s,n);

    }

    public void addstudentmap(String stunum,Object o){
        hs.put(stunum,o);


    }

    public void addstudentinfo(){
       Boolean out = true;

       while(out)
       {
           System.out.println("请输入学号、姓名");
           System.out.print("学号:");
           Scanner s = new Scanner(System.in);
           String stunum = s.next();
           System.out.print("姓名:");
           Scanner n = new Scanner(System.in);
           String name = n.next();
           Studentinfooper newstu1 = new Studentinfooper(stunum,name);
           this.addstudentmap(stunum,newstu1);
           out = this.out();
       }


    }
    public void display(){
        System.out.println("显示所有学生信息:");

        for(Object o : hs.keySet())
        {
            Studentinfo s = (Studentinfo)hs.get(o);

            System.out.println("学号:" + s.getstunum() + "/t姓名:" + s.getname() + "/t成绩" + s.getscore());

        }
    }

    public void delstudeninfo(){
    Boolean out = true;
        while(out){
            System.out.print("请输入你要删除的学号:");
            Scanner s = new Scanner(System.in);
            String stunum = s.next();
            hs.remove(stunum);
            display();
            out = out();
        }
      }

    public void editscore(){
       Boolean out = true;

       while(out)
       {
           Boolean find = false;
           System.out.print("请输入你要修改成绩姓名:");
           Scanner s = new Scanner(System.in);
           String stuname = s.next();

           for(Object o : hs.keySet())
           {

               Studentinfo stu = (Studentinfo)hs.get(o);

               if (stu.getname().equals(stuname)){
                  System.out.println("学号:" + stu.getstunum() + "/t姓名:" + stu.getname() + "/t成绩" + stu.getscore());
                  System.out.print("请输入你要修改的成绩:");
                  Scanner score = new Scanner(System.in);

                  stu.setscore(score.nextDouble());
                  hs.put(stu.getstunum(),stu);
                  find = true;

               }
           }
           if (find == false)
               System.out.println("没有找到该姓名的学生!");
          out = out();
       }
    }

    public void stuavg(){

        double avg = 0;

        for(Object o : hs.keySet()){
             Studentinfo s = (Studentinfo)hs.get(o);
             avg = avg + s.getscore();
         }

        System.out.println("平均成绩:" + avg/hs.size());
    }

    public void displaystuinfo(){
        display();
        System.out.println("显示优秀、良好、中等、不及格的百分比:");
        int y=0,l=0,z=0,b=0;

        for(Object o : hs.keySet())
         {
             Studentinfo s = (Studentinfo)hs.get(o);
             if (s.getscore() >=90)
                 y++;
             else if (s.getscore() >= 75 && s.getscore() <= 89)
                 l++;
             else if (s.getscore() >= 60 && s.getscore() <= 74)
                 z++;
             else
                 b++;
         }

         System.out.println("优秀人数为:" + y*1.0/hs.size()*100 + "%");
         System.out.println("良好人数为:" + l*1.0/hs.size()*100 + "%");
         System.out.println("中等人数为:" + z*1.0/hs.size()*100 + "%");
         System.out.println("不及格人数为:" + b*1.0/hs.size()*100 + "%");
    }

    public void findscore(){
       Boolean out = true;

       while(out)
       {
           Boolean find = false;
           System.out.print("请输入你要查询的学号:");
           Scanner sn = new Scanner(System.in);
           String stunum = sn.next();

           for (Object o : hs.keySet()) {
               Studentinfo s = (Studentinfo) hs.get(o);
               if (s.getstunum().equals(stunum))
               {
                   System.out.println("学号:" + s.getstunum() + "/t姓名:" +
                                      s.getname() + "/t成绩" + s.getscore());
                   find = true;
               }

           }
           if (find == false)
               System.out.println("没有找到!");
           out = out();
       }
    }

    public Boolean out(){
            System.out.print("是否退出?(Y/N):");
            Scanner o = new Scanner(System.in);
            String ifnoout = o.next();
            if (ifnoout.equals("Y") || ifnoout.equals("y"))
              return false;
           else
               return true;

    }

}

public class StudentResultManageClass {
    public StudentResultManageClass() {

    }
    public static void main(String[] args) {
       Studentinfooper newstu = new Studentinfooper();
        newstu.addstudentinfo();
        newstu.display();
        newstu.delstudeninfo();
        newstu.editscore();
        newstu.stuavg();
        newstu.displaystuinfo();
        newstu.findscore();

 

    }
}

 

刚学JAVA才一个月左右,发现写程序还是有点困难,虽然最终还是写出来了,但是时间却用了许多

还有许多地方都感觉到不足,这个程序让我学到3个方面,一个是同一对象的数据是不同的空间,而方

法是同一空间,Hashmap PUT个同一键,而内容不同覆盖原来的键,还有remove()删除要什么同步性

一直搞不清楚,真够菜的,最后一点是好像忘了饿,昨晚还记得起来的,郁闷。从ECLIPSE到

JBUILDER2006发现JBULIDER2006还真是难用呀!

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 手术后纱布掉了怎么办 中国单身的老了怎么办 双眼杯盘比增大,怎么办 出完精子腰疼怎么办 备孕2年没怀孕怎么办 发现怀孕了不想要怎么办 造影后通而不畅怎么办 脑梗病人晚上闹怎么办 两眼视力差距400怎么办 脑血清颗粒吃多怎么办 脸过敏吃了海鲜怎么办 如果qq密码忘了怎么办 qq密码被盗了该怎么办 qq号被别人盗了怎么办 qq不想让别人用怎么办 买了金科的房子怎么办 蟹爪莲叶子耷拉怎么办 金钻的叶子发黄怎么办 金钻叶子发焦黄怎么办 红钻叶子黄了怎么办啊 绿钻叶子黄斑点怎么办 金钻的叶子卷怎么办 金钻叶子有黑斑怎么办 怀孕60天没有胎心胎芽怎么办 单位不给交社保怎么办 公司没给足产假怎么办 小公司不给产假怎么办 机关不给陪产假怎么办 刚人流后又怀孕怎么办 怀孕50天不想要怎么办 生了孩子不想要怎么办 刚怀孕不想要孩子怎么办 怀孕一周不想要孩子怎么办 怀孕了不想要孩子怎么办 怀上二胎后悔了怎么办 50岁怀了二胎怎么办 老公那方面太强怎么办 被私人医院骗了怎么办 我特别烦我妈怎么办 刚怀孕了有炎症怎么办 怀孕了但有炎症怎么办