class Student{
private String stuno ;
private String name ;
private float math ;
private float english ;
private float computer ;
public Student(){}
public Student(String s,String n,float m,float e,float c){
this.setStuno(s) ;
this.setName(n) ;
this.setMath(m) ;
this.setEnglish(e) ;
this.setComputer(c) ;
}
public void setStuno(String s){
stuno = s;
}
public void setName(String n){
name = n;
}
public void setMath(float m )
{
math = m;
}
public voidsetEnglish(float e){
english = e;
}
public void setComputer(float c)
{
computer = c;
}
public float getEnglish(){
return english;
}
public StringgetStuno()
{
return stuno;
}
public String getName()
{
return name;
}
public float getMath(){
return math;
}
public float getComputer()
{
return computer;
}
public float sum(){
return math + computer + english ;
}
public float avg(){
return this.sum()/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;
}
}
public class Ater2{
public static void main(String args[]){
Student stu = null ;// 声明对象
stu = new Student("78","张三",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.max()) ;
System.out.println("最低分:" + stu.min()) ;
System.out.print("平均分:"+stu.avg());
System.out.print("总分:"+stu.sum());
}
};
转载于:https://blog.51cto.com/crhack/1224786