我的代码如下:
package student;
public class Student {
private String idNumber;
private int creditHoursEarned;
private int pointsEarned;
public Student(){
this.idNumber = "9999";
this.creditHoursEarned = 3;
this.pointsEarned = 12;
}
public String getIdNumber() {
return idNumber;
}
public void setIdNumber(String idNumber) {
this.idNumber = idNumber;
}
public int getCreditHoursEarned() {
return creditHoursEarned;
}
public void setCreditHoursEarned(int creditHoursEarned) {
this.creditHoursEarned = creditHoursEarned;
}
public int getPointsEarned() {
return pointsEarned;
}
public void setPointsEarned(int pointsEarned) {
this.pointsEarned = pointsEarned;
}
public double calculateGpa() {
double gradePointAverage = (double)pointsEarned / creditHoursEarned;
return gradePointAverage;
}
public String toString() {
return "Student --"+
"Id Number: " + idNumber+
", Credit Hours Earned: " + creditHoursEarned+
", Points Earned: " + pointsEarned;
}
}
当我尝试在Netbeans IDE 7.4中运行它时,我得到和错误:
student.Student class wasn't found in Student project
这很可能与您的打包结构有关,要么创建一个名为student
的新包并将该类保存在其中,要么尝试从文件顶部删除package student;