我的代码中出现错误(这是我作业的最后一行,我似乎无法解决它),它位于 addStudent 方法中。它说我尝试访问重载的构造函数实际上是在尝试访问默认构造函数,并且没有变量可供我通过。所以,简而言之:
“studentArray[i] = new Student(firstname, lastname, gender, sClass, sID);”
正在尝试访问:
“公共无效学生(){}”
但我希望它访问:
“公共无效学生(字符串名字,字符串姓氏,字符串性别,字符串sClass,字符串sID)”
谢谢您的帮助!
-安德烈斯
public void Student()
{
setFirstName("Unknown");
setLastName("Unknown");
setGender("Unknown");
setClass("Freshman");
setID("0000");
}
public void Student(String firstname, String lastname, String gender, String sClass, String sID)
{
setFirstName(firstname);
setLastName(lastname);
setGender(gender);
setClass(sClass);
setID(sID);
}
public static boolean addStudent(String firstname, String lastname, String gender, String sClass, String sID)
{
for (int i=0; i<studentArray.length; i++)
{
if (studentArray[i] == null)
{
studentArray[i] = new Student(firstname, lastname, gender, sClass, sID);
totStudent++;
}else {JOptionPane.showMessageDialog(null, "Max students reached.");}
}
return true;
}