程式我写好了, 但是好像还跑不起来, 谁能帮我改一下, 最好是能改好后发个完整的上来, 因为光说有时候我还是搞不清楚, 谢谢各位帮忙了
public class Student
{
public String name = "";
public double test1;
public double test2;
public double test3;
public double sum;
public double average;
public double highScore;
public String statement = "";
public void setName(String newName ) {
name = newName;
}
public String getName() {
return name;
}
public void setScore(int whichTest, double testScore) {
//case statement for each test
switch (whichTest){
case 1: test1 = testScore; break;
case 2: test2 = testScore; break;
case 3: test3 = testScore; break;
}
}
public double getAverage() {
sum = test1 + test2 + test3;
average = sum / 3.0;
return average;
}
public double getHighScore() {
if (test1 > test2 && test1 > test3){
highScore = test1;
}else if (test2 > test1 && test2 > test3) {
highScore = test2;
}else if (test3 > test1 && test3 > test2){
highScore = test3;
}
return highScore;
}
public String toString() {
statement = "Name: " + name + "\nTest One: " + test1 + "\nTest Two: " + test2 + "\nTest Three: " + test3 + "\n";
return statement;
}
}
class StudentDemo
{
public static void main(String[] args) {
Student stu1 = new Student(); //Creates student one,
Student stu2 = new Student(); //Creates student two,
stu1.setName("Mark Richter"); //Name for student one
stu1.setScore(1, 90); //scores for student one
stu1.setScore(2, 80);
stu1.setScore(3, 85);
stu2.setName("Bad Student"); //Name for student two
stu2.setScore(1, 42); //scores for student two
stu2.setScore(2, 61);
stu2.setScore(3, 55);
//System.out.print("Name: " + stu1.getName() + "\nAverage Score: " + stu1.getAverage() + "\nHigh Score: " + stu1.getHighScore());
System.out.print(stu1.toString() + "\n\n" + stu2.toString());
}
}