//adds the Students
case 1:
//creates a space
System.out.println();
//asks the user to enter their first name
System.out.print(Util.setLeft(22,"Please enter the student's first name : "));
//reads the firstname from the user
fName = Keyboard.readString();
//asks the user for their last name
System.out.print(Util.setLeft(22, "Please enter the student's last name : "));
//reads the last name from the user
lName = Keyboard.readString();
//asks the user for their last name
System.out.print(Util.setLeft(22, "Please enter the student semester's name: "));
//reads the last name from the user
semName = Keyboard.readString();
//sends the students information to the StudentInfo class
student.StudentInfo(fName, lName, semName);
//creates a space
System.out.println();
//exits the switch
break;
public void StudentInfo(String fNam, String lNam, String semNam)
{
//Local Constants
//Local variables
/******************** Start StudentInfo constructor method *****************/
this.fName = fNam;
this.lName = lNam;
this.semName = semNam;
}//ends the constructor
答案 0 :(得分:0)
StudentInfo构造函数方法仅在创建新类时有效。 在创建类之后,您无法执行此操作。 尝试使用student.setFnam ...
答案 1 :(得分:0)
你可以这样做:
StudentInfo sti = StudentInfo(fName, lName, semName);
但是在StudentInfo
类中,你必须有一个构造函数来接受这样的数据:
class StudentInfo {
String fName;
...
public StudentInfo(String fName, String lName, String semName) {
this.fName = fName;
...
}
}