-3
基本上我有一些数组,我想让用户改变一些数据,如果他想通过用户输入。我想我应该使用扫描仪,但我不完全清楚如何做到这一点。如何通过用户输入更改数组中的对象?
的数组存储在一个类中调用数据库
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
这是阵列中的数据被称为在另一个类叫学生。
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的方法,并打印出所有的学生。
这不是一个问题。尝试过某些东西后,请回复一个具体问题。 – aliteralmind
很简单,将* setter *和* getter *方法添加到'Student'类。 'arrayStudents [0] .setUsername(“....”)'......等等。 – Azad
我改变了这个问题,我也提出了更清晰的问题。我希望这可以帮助您再次查看问题,并希望得到帮助。 – user3383541