【发布时间】:2016-02-14 01:22:52
【问题描述】:
我创建了以下数组列表:
premierLeague = new ArrayList<FootballClub>();
我有以下代码创建一个 FootballClub 对象并将其放入数组列表中:
System.out.println("Name of club:");
String name = input.next();
System.out.println("Location of club:");
String location = input.next();
FootballClub newClub = new FootballClub(name, location); // If only the name and location are placed in the new object, does that mean that all other stats are set to 0?
premierLeague.add(newClub);
System.out.println("Football club added! size = " + premierLeague.size());
我还有以下代码来遍历数组列表,以检查用户输入的 FootballClub 名称是否与数组列表中的 FootballClub 对象匹配。
Iterator<FootballClub> it = premierLeague.iterator();
while (it.hasNext()) {
if (it.next().getClubName().equals(homeName)) {
}
}
Football 类还有其他方法(除了name 和location),例如gamesWon、gamesLost 和Points。如何允许用户输入足球俱乐部的名称和得分,然后将其添加到现有对象中?例如,如果用户输入 'Arsenal' 作为俱乐部,得分为 2,程序应找到名称为“Arsenal”的对象,然后将得分 2 添加到对象内的Pointsmethod。
FootballClub 类具有所有变量的 getter 和 setter。
【问题讨论】:
-
问题不清楚。您遇到错误了吗?
-
这听起来像是报告而不是问题...