学生类 总分 平均分 最高分 和 最低分的 java代码

来源:互联网 发布:gm300写频软件 编辑:程序博客网 时间:2024/04/30 15:04
  课程练习:
package javademo.bailu;public class Student {private int code;private String name;private double  macth;private double english;private double computer;public int getCode() {return code;}public void setCode(int code) {this.code = code;}public String getName() {return name;}public void setName(String name) {this.name = name;}public double getMacth() {return macth;}public void setMacth(double macth) {this.macth = macth;}public double getEnglish() {return english;}public void setEnglish(double english) {this.english = english;}public double getComputer() {return computer;}public void setComputer(double computer) {this.computer = computer;}public Student(int code, String name, double macth, double english,double computer) {super();this.code = code;this.name = name;this.macth = macth;this.english = english;this.computer = computer;}public double sum(){double res = macth+english+computer;return res;}public double avg(){double res = (macth+english+computer)/3;return res;}public double max(){double res;if(english>macth){if(english>computer){res=english;}else{res=computer;}}else{if(macth>computer){res=macth;}else{res=computer;}}return res;}public double min(){double res;if(english<macth){if(english<computer){res=english;}else{res=computer;}}else{if(macth<computer){res=macth;}else{res=computer;}}return res;}public static void main(String[] args) {Student st = new Student(1,"bai",80,103,90);System.out.println("总分是:"+st.sum());System.out.println("平均分是:"+st.avg());System.out.println("最大值是:"+st.max());System.out.println("最小值是:"+st.min());}}

原创粉丝点击