if if 与if else if 引发的错误

class Student{
private String stuno;
private String name;
private float math;
private float english;
private float computer;
public Student(){}
public Student(String stuno,String name,float math,float english, float computer){
this.setStuno(stuno);
this.setName(name);
this.setMath(math);
this.setEnglish(english);
this.setComputer(computer);

}
public String getStuno(){
return stuno;
}
public void setStuno(String s){
stuno=s;

}
public String getName(){
return name;
}
public void setName(String n){
name=n;
}
public  float getMath(){
return math;
}
public void setMath(float m){
math=m;
}
public float getEnglish(){
return english;
}
public void setEnglish(float e){
english=e;
}
public float getComputer(){
return computer;
}
public void setComputer(float c){
computer=c;
}

public float  sum(){
float sum=math+english+computer;
return sum;

}
public float avg(){

return this.sum()/3;
}
public float max(){
float max=math;
if(english>max){
max=english;
}
if(computer>max){
//此处如果用的是ELSE IF 则输出的结果为最大值为4,显然是错愕,因为 第一个if 已经满足条件不会继续执行下去,是互斥的关系,而用IF 则是并列的关系,每一种情况都要执行判断
max=computer;
}
return max;
}
public float min(){
float min=math;
if(english<min){
min=english;
}
if(computer<min){
min=computer;
}
return min;
}

}
public class ExampleDemo1 {
public static void main(String args[]){
  Student stu=new Student("13","冯晓辉",3,4,5);
     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.sum());
     System.out.println("平均成绩"+stu.avg());
     System.out.println("最高成绩"+stu.max());
     System.out.println("最低成绩"+stu.min());
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值