成绩
package 成绩;
public class Grade {
private
double biology;
double math;
double english;
public Grade(double b, double m, double e)
{
b= biology;
m= math;
e = english;
}
public double total() {
return biology + math + english;
}
public void printTotal() {
System.out.println(total());
}
public double average() {
return total() / 3;
}
public void printAverage() {
System.out.println(average());
}
public double getbiology() {
return biology;
}
public void setbiology(double biology) {
this.biology = biology;
}
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(100, 94, 90));
s.grade.printAverage();
s.grade.printTotal();
}
}
结果:
94.66666
284.0