第三十四天 綜合示例

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());

}

};


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章