我对Java很新,所以如果这看起来像一个愚蠢的问题,请原谅我。
我有3个班,其中一个是主班。
1级 - 级帐户。只包含空变量/对象
String firstName;
int age;
2级 - 班级随机。包含许多名称的数组,并包含随机选择名称和随机选择年龄的方法:
String Names[] = {"Sophia", ....., "Sasha", "James"}; // About a 100 names
public void nameRandom(String name) {
name = Names[rand.nextInt(Names.length)];
}
public void ageRandom(int age){
age = rand.nextInt(64)+19;
}
最后,Class 3,主类('howManyAccounts'是通过扫描仪获得的整数):
Account[] accounts = new Account[howManyAccounts];
for (int i = 0; i < accounts.length; i++){
accounts[i] = new Account();
random.nameRandom(accounts[i].firstName);
random.ageRandom(accounts[i].age);
}
System.out.println("NAME" + " " + "AGE");
System.out.println("");
for (int x = 0; x < accounts.length; x++){
System.out.println(accounts[x].firstName + " " + accounts[x].age);
}
The variables are never saved and I can't seem to figure out why.