package student;
class InOfStudent{
private String name;
private int age;
private double computer;
private double english;
private double math;
public InOfStudent(){}//构造方法
public InOfStudent(String n,int a,double c,double e,double m){
this.setName(n);
this.setAge(a);
this.setComputer(c);
this.setEnglish(e);
this.setMath(m);
}
public String getName() {//姓名
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {//
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getComputer() {//
return computer;
}
public void setComputer(double computer) {
this.computer = computer;
}
public double getEnglish() {//
return english;
}
public void setEnglish(double english) {
this.english = english;
}
public double getMath() {//
return math;
}
public void setMath(double math) {
this.math = math;
}
public double score(){
return (this.computer + this.english + this.math);
}
public double average(){
return((this.computer + this.english + this.math)/3);
}
public double top(){
double max;
max = this.computer > this.english ? this.computer : this.english;
max = max > this.math ? max : this.math;
return max;
}
public double down(){
double min;
min = this.computer < this.english ? this.computer : this.english;
min = min < this.math ? min : this.math;
return min;
}
}
public class Student {
public static void main(String[] args) {
InOfStudent person = new InOfStudent("嘟嘟",19,79,80,90);
System.out.println("姓名:" + person.getName() + "\n" + "年龄:" + person.getAge() + "\n" + "计算机:" + person.getComputer() + "\n" + "英语:" + person.getEnglish() + "\n" + "数学:" + person.getMath());
System.out.println("总分:" + person.score());
System.out.println("平均分:" + person.average());
System.out.println("最高分:" + person.top());
System.out.println("最低分:" + person.down());
}
}
代码运行结果:
姓名:嘟嘟
年龄:19
计算机:79.0
英语:80.0
数学:90.0
总分:249.0
平均分:83.0
最高分:90.0
最低分:79.0
本文介绍了一个简单的Java程序,用于创建学生对象,并记录学生的姓名、年龄及三门课程的成绩。程序还提供了计算总分、平均分、最高分及最低分的方法。
2万+

被折叠的 条评论
为什么被折叠?



