隨筆 - 20  文章 - 57  trackbacks - 0
          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          51CTO

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          //新建一個StudentList類
          //-------------------------------------------


          //Student類
          //-------------------------------------------




          package Student_Level;
          //新建一個Student類
          public class Student {
           int id;
           String name;
           String sex;
           int age;
           int score;
           String remark;
           
           public Student(int id, String name, String sex, int age, int score, String remark){
            this.id = id;
            this.name = name;
            this.sex = sex;
            this.age = age;
            this.score = score;
            this.remark = remark;
           }

           public int getId() {
            return id;
           }

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

           public String getName() {
            return name;
           }

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

           public String getSex() {
            return sex;
           }

           public void setSex(String sex) {
            this.sex = sex;
           }

           public int getAge() {
            return age;
           }

           public void setAge(int age) {
            this.age = age;
           }

           public int getScore() {
            return score;
           }

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

           public String getRemark() {
            return remark;
           }

           public void setRemark(String remark) {
            this.remark = remark;
           }
          }








          //StudentList類
          //-------------------------------------------



          public class StudentList {
           public static void main(String[] args){
            //新建5個Student學生對象并實例化
            Student[] student = new Student[5];
            Student stu1 = new Student(2010001, "張三", "男", 22, 89, " ");
            student[0] = stu1;
            
            Student stu2 = new Student(2010002, "王四", "男", 23, 88, " ");
            student[1] = stu2;
            
            Student stu3 = new Student(2010003, "張吾", "女", 20, 79, " ");
            student[2] = stu3;
            
            Student stu4 = new Student(2010004, "劉六", "女", 19, 90, " ");
            student[3] = stu4;
            
            Student stu5 = new Student(2010005, "林子", "男", 22, 50, " ");
            student[4] = stu5;
            
            //新建5個變量用來記錄優秀等學生的人數
            int excellence = 0;
            int good = 0;
            int pass = 0;
            int nopass = 0;
            int rebuild = 0;
            
            //新建5個整數數組用來存放優秀等人在stu數組中的下標
            int[] ex = new int[5];
            int[] go = new int[5];
            int[] pa = new int[5];
            int[] no = new int[5];
            int[] re = new int[5];
            
            //便利student數組,根據學生成績判斷學生的優略
             for(int i=0;i<student.length;i++){
             int stud = student[i].score/10;
             switch(stud){
             case 9 : {
              ex[excellence] = i;
              excellence++;
              break;
             }
             case 8 : {
              go[good] = i;
              good++;
              break;
             }
             case 7 : {
              pa[pass] = i;
              pass++;
              break;
             }
             case 6 : {
              no[nopass] = i;
              nopass++;
              break;
             }
             default : {
              re[rebuild] = i;
              rebuild++;
              break;
             }
             }
            }
             //打印優秀等學生的人數
                  System.out.println("成績為優秀的人數為:    " + excellence);
                  System.out.println("成績為良好的人數為:    " + good);
                  System.out.println("成績為及格的人數為:    " + pass);
                  System.out.println("成績為不及格人數為:    " + nopass);
                  System.out.println("成績需要重修人數為:    " + rebuild);
                  System.out.println();
                  
                  //打印獲得優秀等成績同學的信息
                  System.out.println("成績為優秀的同學為:");
                  System.out.println("**********************************************************");
                  System.out.println("    學號    \t      " + "  姓名" + "  性別" + " 成績" + "    備注");
                  for(int i=0;i<excellence;i++){
                   System.out.println(student[ex[i]].id + "    " + student[ex[i]].name + "    " + student[ex[i]].sex + "      " + student[ex[i]].score + "    " + student[ex[i]].remark);
                  }
                  System.out.println();
                  System.out.println("成績為良好的同學為:");
                  System.out.println("**********************************************************");
                  System.out.println("    學號    \t      " + "  姓名" + "  性別" + " 成績" + "    備注");
                  for(int i=0;i<good;i++){
                   System.out.println(student[go[i]].id + "    " + student[go[i]].name + "    " + student[go[i]].sex + "      " + student[go[i]].score + "    " + student[go[i]].remark);
                  }
                  System.out.println();
                  System.out.println("成績為及格的同學為:");
                  System.out.println("**********************************************************");
                  System.out.println("    學號    \t      " + "  姓名" + "  性別" + " 成績" + "    備注");
                  for(int i=0;i<pass;i++){
                   System.out.println(student[pa[i]].id + "    " + student[pa[i]].name + "    " + student[pa[i]].sex + "      " + student[pa[i]].score + "    " + student[pa[i]].remark);
                  }
                  System.out.println();
                  System.out.println("成績為不及格的同學為:");
                  System.out.println("**********************************************************");
                  System.out.println("    學號    \t      " + "  姓名" + "  性別" + " 成績" + "    備注");
                  for(int i=0;i<nopass;i++){
                   System.out.println(student[no[i]].id + "    " + student[no[i]].name + "    " + student[no[i]].sex + "      " + student[no[i]].score + "    " + student[no[i]].remark);
                  }
                  System.out.println();
                  System.out.println("成績差需要重修的同學為:");
                  System.out.println("**********************************************************");
                  System.out.println("    學號    \t      " + "  姓名" + "  性別" + " 成績" + "    備注");
                  for(int i=0;i<rebuild;i++){
                   System.out.println(student[re[i]].id + "    " + student[re[i]].name + "    " + student[re[i]].sex + "      " + student[re[i]].score + "    " + student[re[i]].remark);
                  }
           }
          }



          //如果大家有什么意見或者看不懂,請大家留下你們的建議
          posted on 2010-10-10 16:26 tovep 閱讀(226) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主頁
          主站蜘蛛池模板: 梓潼县| 萨迦县| 慈利县| 西充县| 仪陇县| 镇赉县| 南宁市| 叶城县| 方正县| 莫力| 平遥县| 郴州市| 永城市| 米林县| 伊川县| 蒲江县| 濮阳县| 开平市| 来宾市| 休宁县| 乐清市| 杭州市| 科尔| 阿坝县| 栾川县| 灵石县| 三原县| 西林县| 芦溪县| 广西| 全州县| 内丘县| 桂东县| 神池县| 信阳市| 子洲县| 大连市| 九龙县| 印江| 五寨县| 敦化市|