У меня проблема в TestVolleyTeam. java. Я не могу заставить массивы списка работать, я честно запутался. Я действительно не знаю, как назначить списки с «для» l oop, я, вероятно, ошибся там. Код должен отображать список игроков, используя класс VolleyPlayer и класс VolleyTeam через класс TestVolleyTeam. Кто-нибудь может определить ошибки, которые я сделал?
class VolleyPlayer {
private String name;
private String surname;
private int flnum;
private int height;
public String getName() {
return name;
}
public String getSurname() {
return surname;
}
public int getFlnum() {
return flnum;
}
public int getHeight() {
return height;
}
public VolleyPlayer(String n, String sur, int fl, int h) {
name = n;
surname = sur;
flnum = fl;
height = h;
}
public VolleyPlayer(String n, String sur, int fl) {
this(n, sur, fl, 185);
}
public VolleyPlayer(String n, String sur) {
this(n, sur, 3);
}
public VolleyPlayer(String n) {
this(n, "Brown");
}
}
import java.util.ArrayList;
public class VolleyTeam {
private String teamname;
private String city;
private int year;
private ArrayList<VolleyPlayer> players;
public String getTeamname() {
return teamname;
}
public String getCity() {
return city;
}
public int getYear() {
return year;
}
public ArrayList<VolleyPlayer> getPlayers() {
return players;
}
public void setTeamname(String newTeamname) {
this.teamname = teamname;
}
public void setCity(String newCity) {
this.city = city;
}
public void setYear(int newYear) {
this.year = year;
}
public void setPlayers(ArrayList<VolleyPlayer> newPlayers) {
this.players = players;
}
}
import javax.swing.JOptionPane;
import java.util.Scanner;
import java.util.ArrayList;
public class TestVolleyTeam {
public static void main(String[] args) {
VolleyTeam myObj = new VolleyTeam();
String teamname = JOptionPane.showInputDialog(null, "What is the name of the team?", "Input");
myObj.setTeamname(teamname);
String city = JOptionPane.showInputDialog(null, "What is the city of the team?", "Input");
myObj.setCity(city);
String input = JOptionPane.showInputDialog(null, "What is the foundation year of the team?",
"Input");
int year = Integer.parseInt(input);
myObj.setYear(year);
myObj.getTeamname();
myObj.getCity();
myObj.getYear();
VolleyPlayer first = new VolleyPlayer("Michael", "Scott", 1, 175);
VolleyPlayer second = new VolleyPlayer("Jim", "Halpert", 2, 191);
VolleyPlayer third = new VolleyPlayer("Dwight", "Schrute", 3, 189);
VolleyPlayer fourth = new VolleyPlayer("Darryl", "Philbin", 4, 188);
VolleyPlayer fifth = new VolleyPlayer("Andy", "Bernard", 5, 182);
VolleyPlayer sixth = new VolleyPlayer("Oscar", "Martinez", 6, 173);
VolleyPlayer seventh = new VolleyPlayer("Stanley", "Hudson", 7, 180);
VolleyPlayer eighth = new VolleyPlayer("Kevin", "Malone", 8, 185);
VolleyPlayer ninth = new VolleyPlayer("Creed", "Bratton", 9, 183);
VolleyPlayer tenth = new VolleyPlayer("Toby", "Flederson", 10, 177);
ArrayList<VolleyPlayer> vplist = new ArrayList<VolleyPlayer>();
for (VolleyPlayer volleyPlayer : vplist) {
vplist.add(volleyPlayer);
}
myObj.getPlayers();
myObj.setPlayers(vplist);
ArrayList<VolleyPlayer> vplist2 = volleyTeam.getPlayers();
for (VolleyPlayer volleyPlayer : vplist2) {
vplist2.add(volleyPlayer);
}
volleyTeam.getPlayers();
volleyTeam.setPlayers(vplist2);
JOptionPane.showMessageDialog(null, vplist2, teamname + " " + city + ", " + year,
JOptionPane.INFORMATION_MESSAGE);
}
}