1根据要求写出类所包含的属性。

2所有的属性都必须进行封装(private)

3封装之后的属性通过setter和getter设置和取得

4如果需要可以加入若干构造方法

5再根据其他要求添加相应的方法

6类中的所有方法都不要直接输出,而是交给被调用处输出。

package day06;
class Student{                                                                               //定义学生类
      private String name;                                                                   //学生姓名
      private  String stuno;                                                                 //学生编号
      private float math;                                                                    //数学成绩
      private float English;                                                                 //英语成绩
      private float computer;                                                                //计算机成绩
      public Student() {
                                                                                               //定义无参构造
      }
   public Student(String stuno,String name,float math,float English,float computer) {    //定义5个参数的构造方法,为类中的属性初始化
       this.setStuno(stuno);                                                              //设置编号
       this.setName(name);
       this.setMath(math);
       this.setEnglish(English);
       this.setComputer(computer);
   }
   public void setStuno(String s) {                                                         //设置编号
      stuno=s;
   }
   public void setName(String n) {
       name=n;
   }
   public void setMath(float m) {
       math=m;
   }
   public void setEnglish(float r) {
       English=r;
   }
   public void setComputer(float e) {
       computer=e;
   }
   public String getStuno(){                                                                //取得编号
       return stuno;
   }
   public String getName() {
       return name;
   }
   public float getMath() {
       return math;
   }
   public float getEnglish() {
       return English;
   }
   public float getComputer() {
       return computer;
   }
   public float sum() {                                                                        //计算总分
       return math+English+computer;
   }
   public avg() {
       return this.sum()/3;
   } 
   public float max() {                                                                        //最高成绩
       float max=math;                                          
       max=max>computer?max:computer;
       max=max>English?max:English;                                                            //使用三目运算符
       return max;
   }
   public float min() {
       float min=math;
       min=min<computer?min:computer;
       min=min<English?min:English;
       return min;
   }
}

public class day06 {
    public static void main(String args[]) {
           Student stu=null;
           stu =new Student("MLDN-33","李华",95.0f,89.0f,96.0f);
           System.out.println("学生编号: "+stu.getStuno());
           System.out.println("学生姓名: "+stu.getName());
           System.out.println("数学成绩: "+stu.getMath());
           System.out.println("英语成绩: "+stu.getEnglish());
           System.out.println("计算机成绩:"+stu.getComputer());
           System.out.println("最高分:"+stu.max());
           System.out.println("最低分:"+stu.min());
           
    }
}

 

posted on 2020-03-05 20:12  听风说你  阅读(151)  评论(1)    收藏  举报