标签:print out ati IV int his get etc main
public class Grade {
private double chinese; //语文成绩
private double math; //数学成绩
private double english; //英语成绩
public Grade(double chinese, double math, double english) //构造函数
{
this.chinese= chinese;
this.math = math;
this.english = english;
}
public double total() { //计算总成绩
return chinese + math + english;
}
public void printTotal() { //输出总成绩
System.out.println(total());
}
public double average() { //计算平均值
return total() / 3;
}
public void printAverage() { //输出平均值
System.out.println(average());
}
public double getchinese() { //获取语文成绩
return chinese;
}
public void setchinese(double chinese) {
this.chinese = chinese;
}
public double getMath() { //获取数学成绩
return math;
}
public void setMath(double math) {
this.math = math;
}
public double getenglish() { //获取英语成绩
return english;
}
public void setenglish(double english) {
this.english = english;
}
}
class Student {
String name; //学生姓名
Grade grade; //成绩
public Student(String name, Grade grade) {
this.name = name;
this.grade = grade;
}
public static void main(String[] args) { //主程序调用
Student s = new Student("Cici", new Grade(89, 78, 98));
s.grade.printAverage();
s.grade.printTotal();
}
}
设计10名学生成绩信息,同学有3门课程,计算同学的总成绩和平均分。 排序输出
标签:print out ati IV int his get etc main
原文地址:https://www.cnblogs.com/gt33/p/9102790.html