要求:给定一组学生的信息,包括:姓名、年龄、成绩、班级、等级。将学生的成绩划分等级,并输出。

1  新建Student类,定义学生的属性
 

package com.dr.test;

public class Student {
 private String name;
 private int age;
 private int score;
 private String department;
 private String level;
 
 public int getScore(){
  return score;
 }

 public void setScore(int score) {
  this.score = score;
 }
    public String getName(){
     return name;
    }
    public void setName(String name){
     this.name=name;
    }
    public int getAge(){
     return age;
    }
    public void setAge(int age){
     this.age=age;
    }
    public String getDepartment(){
  return department;
     
    }
    public void setDepartment(String department){
     this.department=department;
    }
    public String getLevel(){
     return level;
    }
    public void setLevel(String Level){
     this.level=level;
    }
}


2 创建StudentTest类,新建学生对象,将学生的成绩划分等级,并输出

package com.dr.test;

public class StudentTest {

 


 public static void main(String[] args) {
  Student[] stuArr=new Student[4];
 //######################################## 
  Student student=new Student();
  student.setName("宋可");
  student.setAge(23);
  student.setScore(62);
  student.setDepartment("计算机科学系");
  stuArr[0]=student;
 //#######################################  
  Student student1=new Student();
  student1.setName("田馨");
  student1.setAge(25);
  student1.setScore(80);
  student1.setDepartment("音乐系");
  stuArr[1]=student1;
 //######################################## 
  Student student2=new Student();
  student2.setName("晓枫");
  student2.setAge(30);
  student2.setScore(78);
  student2.setDepartment("美术系");
  stuArr[2]=student2;
 //########################################
        Student student3=new Student();
        student3.setName("林岚");
        student3.setAge(25);
        student3.setScore(90);
        student3.setDepartment("中文系");
        stuArr[3]=student3;
   
  for(int j=0;j<stuArr.length;j++){
         if(stuArr[j]!=null)  
    System.out.println(stuArr[j].getName()+"   年龄:"+stuArr[j].getAge()+"     成绩:"+stuArr[j].getScore()+"    班级:"+stuArr[j].getDepartment());
  }

   
     for(int i=0;i<stuArr.length;i++){
  if(stuArr[i]!=null){
   int z;
      z=stuArr[i].getScore()/10;
  switch(z){
     case(9):{
         System.out.println(stuArr[i].getName()+"等级为A");
         break;
     }
     case(8):{
         System.out.println(stuArr[i].getName()+"等级为B");
         break;
        
     }
     case(7):{
         System.out.println(stuArr[i].getName()+"等级为C");
         break;
     }
     case(6):{
         System.out.println(stuArr[i].getName()+"等级为D");
         break;
     }
     default:{
         System.out.println(stuArr[i].getName()+"等级为E");
         break;
     }
     }
 }   
 }

}
}