考生类

package paet02;

public class ExampleDemo01 {
public static void main(String[] args) {
Student stu = new Student("MLDN-33","李兴华",95.0f,92.0f,93.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());
System.out.println("总和:"+stu.sum());
System.out.println("平均分:"+stu.avg());
}

}

class Student{
private String stuno;
private String name;
private float math;
private float english;
private float computer;
public String getStuno() {
return stuno;
}
public void setStuno(String stuno) {
this.stuno = stuno;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getMath() {
return math;
}
public void setMath(float math) {
this.math = math;
}
public float getEnglish() {
return english;
}
public void setEnglish(float english) {
this.english = english;
}
public float getComputer() {
return computer;
}
public void setComputer(float computer) {
this.computer = computer;
}
public Student() {

}
public Student(String stuno, String name, float math, float english,
float computer) {
setMath(math);
setEnglish(english);
setComputer(computer);
setName(name);
setStuno(stuno);
}
public float sum(){
return math + english + computer;
}
public float avg(){
return (math + english + computer)/3;
}
public float max(){
float max = math;
max = max > english ? max : english;
max = max > computer ? max : computer;
return max;
}
public float min(){
float min = math;
min = min < english ? min : english;
min = min < computer ? min : computer;
return min;
}
}

猜你喜欢

转载自www.cnblogs.com/wazl/p/11671417.html