隨筆 - 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)  編輯  收藏

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


          網站導航:
           
          主頁
          主站蜘蛛池模板: 兴隆县| 辽宁省| 保山市| 盘山县| 大田县| 青田县| 南木林县| 廉江市| 绩溪县| 阿坝县| 宝应县| 绵阳市| 师宗县| 宁强县| 公安县| 柯坪县| 新巴尔虎右旗| 宜阳县| 高青县| 平湖市| 泌阳县| 萍乡市| 平阳县| 旅游| 富阳市| 谢通门县| 钟山县| 新宁县| 突泉县| 香河县| 台南市| 开阳县| 廊坊市| 濮阳市| 仁怀市| 长武县| 清徐县| 桐乡市| 新余市| 梨树县| 和田市|