随笔 - 20  文章 - 57  trackbacks - 0
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(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 阅读(213) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
 
主页