5.6Student类

来源:互联网 发布:初高中教学网络直播 编辑:程序博客网 时间:2024/06/03 06:23
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 void setStuno(String s){stuno=s;}public void setName(String n){name=n;}public void setMath(float m){math=m;}public void setEnglish(float e){english=e;}public void setComputer(float c){computer=c;}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 float ave(){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 main {public static void main(String[] args){Student stu=null;stu=new Student("MLDN-33","li",95.0f,89.0f,96.0f);System.out.println("stuno:"+stu.getStuno());System.out.println("name:"+stu.getName());System.out.println("math:"+stu.getMath());System.out.println("english:"+stu.getEnglish());System.out.println("computer:"+stu.getComputer());System.out.println("max:"+stu.max());System.out.println("min:"+stu.min());}}

result:

stuno:MLDN-33
name:li
math:95.0
english:89.0
computer:96.0
max:96.0
min:89.0

0 0