这是一个家庭作业,也是我的第一个 Java 程序。我写了一个 StudentAverage 类,现在我想测试类方法,但是当我编写我的测试程序时,IDE 告诉我不能声明我的 main static。我使用 Eclipse 作为我的 IDE。
由于这是一项家庭作业,而且我仍在学习 Java,因此我也希望得到一些关于我做错了什么的指导。
这是我的代码:
/**
*Program: StudentAverage, Calculate the student average quizzes taken
* @author: Jose Mazorra
* Date: July 11, 2013
* Class: CIS406
*/
/**
A student who is taking quizzes.
*/
public class StudentAverage
{
//Instances variables
private String name;
private double quizScores;
private double numOfQuizzesTaken;
/**
Constructs a student with a given name.
@param n the name
*/
public StudentAverage(String stuName)
{
name = (stuName);
}
/**
Gets the name of this student.
@return the name
*/
public String getName()
{
return name;
}
/**
Adds a quiz score.
@param score the score to add
*/
public void addQuiz(int score)
{
numOfQuizzesTaken++;
quizScores = quizScores + score;
}
/**
Gets the sum of all quiz scores.
@return the total score
*/
public double getTotalScore()
{
return quizScores;
}
/**Returns the average of all quiz taken
* by the student
* @return average score
*/
public double getAverageScore(){
double avgScore;
avgScore = (quizScores / numOfQuizzesTaken);
return avgScore;
}
public class StudentAverageTester{
public static void main(String[] args){
StudentAverage student = new StudentAverage()
student.name("Jose");
student.numOfQuizzesTaken(10);
student.quizScores(400);
double avg = student.avgScore();
System.out.println(name);
System.out.println(avg);
System.out.println("Expected 40");
}
}
}