基本上我有很多数组,如果他想通过用户输入,我想让用户更改一些数据。我想我应该使用扫描仪,但我不清楚如何做到这一点。
数组存储在名为database
的类中private Student[] arrayStudents;
public DepotDatabase() {
arrayStudents = new Driver[4];
arrayStudents[0] = new Student("First", "Second", 1234, 1234); // sample student
arrayStudents[1] = new Student("First 1", "Second2" , 4444, 4444); // sample student
这就是在另一个名为Student的类中调用数组中的数据。
public Student(String firstName, String lastName, int username, int password) {
this.firstName = firstName;
this.lastName = lastName;
this.username = username;
this.password = password;
}
并在另一个名为 SetUpCourse 的类中,我想让用户通过用户输入更改学生的姓名,还可以更改用户名,例如 arrayStudent [0] 到 arrayStudent [1] ,如密码
我想我会在 SetUpWorkSchedule
中有这样的东西Scanner scan = new Scanner(System.in);
System.out.println("Please enter a password");
setPassword() = scan.nextLine();
database.printArrayStudent();
现在要打印出数组,我有一个名为 printArrayStudent 的方法,这会打印出所有学生。
答案 0 :(得分:0)
我认为你的Student
课应该是这样的:
public class Student {
private String firstName;
private String lastName;
private String userName;
private String password;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
//and do for other global variables lastName,userNAme,Password..
//parametric constructor
public Student(String firstName, String lastName, int username, int password) {
this.firstName = firstName;
this.lastName = lastName;
this.username = username;
this.password = password;
}
//and default constructor
}
然后您可以更改有关学生的任何信息,如下所示:
arrayStudents[0].setUserName("username");
arrayStudents[0].setFirstName("firstname");
arrayStudents[0].setLastName("lastname");
//......