所以在這個類中選擇== 1,它不會通過對象的ArrayList進入for循環,它是否意味着對象是空的?因爲我在開始時聲明瞭對象並將它們添加到ArrayList存儲中。Arraylist of objects empty?
public static void main(String[] args) {
ArrayList<Team> store = new ArrayList<>();
Random gener = new Random();
String tourName , tourDate , location;
int maxNumberofTeams , avalSoft, avalHard , avalFieldTest;
Scanner input = new Scanner(System.in);
System.out.print("Please Enter tournament Name?\n");
tourName = input.next();
System.out.print("please Enter tournament Date\n");
tourDate = input.next();
System.out.print("please Enter location\n");
location = input.next();
System.out.print("Please Enter Max number of Teams\n");
maxNumberofTeams = input.nextInt();
System.out.print("Please Enter avalSoft\n");
avalSoft = input.nextInt();
System.out.print("Please enter aval Hard\n");
avalHard = input.nextInt();
System.out.print("Please Enter avalFieldTest\n");
avalFieldTest = input.nextInt();
Tournament tour = new Tournament (tourName , tourDate, location , maxNumberofTeams, avalSoft , avalHard, avalFieldTest);
for (int i = 1 ; i <= maxNumberofTeams ; i++)
{
String teamName , sponsoringSchool , financialSponsor , judgeLocation;
int teamNumber , noOfTeamMem , robotId;
System.out.print("Please Enter %s team Name\n");
teamName = input.next();
System.out.print("Number of Team Memebers\n");
noOfTeamMem = input.nextInt();
System.out.print("Please Enter Sponsoring Schoolr\n");
sponsoringSchool = input.next();
System.out.print("Please Enter financialSponsor\n");
financialSponsor = input.next();
System.out.print("Please Enter judge Location\n");
judgeLocation = input.next();
teamNumber = i;
System.out.print("Please Enter an ID for robot\n");
robotId = input.nextInt();
Robot robbb = new Robot();
Team team = new Team(teamName , teamNumber , noOfTeamMem , sponsoringSchool , financialSponsor, judgeLocation, robbb);
Robot rob = new Robot (team , robbb);
store.add(team);
}
int choice=0;
while(choice >= 0)
{
System.out.print("MENU\n"
+ "1)PREPARING TEAM TURN ROBOT ON\n"
+"2)PREPARING TEAM HARDWARE\n"
+ "3)HAVE HW INSPECT READY ROBOT\n"
+ "4)HAVE PRERPARING TEAM TAKE HW_INSPECTED ROBOT TO STATION\n"
+ "5)HAVE SW INSPECT ROBOT\n"
+ "6)HAVE A PREPARING TEAM TAKE TO FIELD TEST\n"
+ "7)HAVE A FIELD TEST INSPEC\n"
+ "8)HAVE A BEFORE TEAM GO TO JUDGE\n"
+ "9)HAVE JUDGES INTERVIEW\n"
+ "10)CHANGE TEAM STATUS TO PASSED_INSPECTION\n"
+ "11)TOURNAMENT STATUS TO MATCH\n"
+ "12)\n"
+ "13)ROBOT CAN'T PLAY IF OFF, READY, OR STILL AT TESTING\n"
+ "14)CHANGE TOURNAMENT TO MATCHES\n"
+ "15)GENERATE POINTS\n"
+ "16)JUDGE POINTS\n"
+ "17)CHANGE TOURNAMENT TO AWARDS\n"
+ "18)PRINT TOP TEAMS JUDGING\n"
+ "19) PRINT TOP BY QULIFYING \n"
+ "20)DISPLAY TEAM PERSONS\n"
+ "21)DISPLAY TEAM INFO\n"
+ "22)DISPLAY INFO ABOUT ROBOTS\n"
+ "23)INFO ABOUT TOURNAMENT\n"
+ "24)END\n");
choice = input.nextInt();
Team temp = new Team();
Robot robottemp = new Robot();
Tournament tourr = new Tournament();
if (choice == 1)
{
System.out.print("Phase"+choice);
for (int i = 0 ; i >= store.size(); i++)
{
System.out.print("Phase"+choice);
store.get(i).teamStatus = temp.teamStatus.PREPARING;
if (store.get(i).teamStatuss == 1)
{
store.get(i).robot.robotStatusChoice(1);
System.out.print("PHASE 1 COMPLETED\n");
}
}
}
這是我在其中調用該方法的機器人類;
public int teamNumber;
public int robotId;
public Robot robot;
Random gener = new Random();
public int robotStatusChoice;
ArrayList stations = new ArrayList();
public int Height;
public int Width = 22;
public int Depth;
public Team TeamAssigned = new Team("TEAMNAME", 1 , 1, "SS", "FS", "JL",robot);
public robotStatus robotStatus;
public Robot()
{
}
public Robot(Team TeamAssigned ,Robot robot){
this.robot = robot;
this.TeamAssigned = TeamAssigned;
}
public void robotStatusChoice(int i) {
if (i == 1)
{
this.robotStatusChoice = i;
this.robotStatus = robotStatus.READY;
}
else if(i == 2)
{
this.robotStatusChoice = i;
this.robotStatus = robotStatus.HW_INSP_PASSED;
}
else if (i == 3)
{
this.robotStatusChoice = i;
this.robotStatus = robotStatus.FIELD_TEST_PASSED;
}
else if (i > 3 || i < 1)
{
this.robotStatusChoice = i;
this.robotStatus = robotStatus.READY;
}
}
TeamSTatus Change;
public void TeamStatus(int x)
{
if(x == 1)
{
this.teamStatuss = x;
this.teamStatus = teamStatus.PREPARING;
}
else if (x == 2)
{
this.teamStatuss = x;
this.teamStatus = teamStatus.PASSED_INSPECTION;
}
else if (x == 3)
{
this.teamStatuss = x;
this.teamStatus = teamStatus.PLAYED5_MATCHES;
}
else if (x == 4)
{
this.teamStatuss = x;
this.teamStatus = teamStatus.INELIGIBLE;
}
else if (x > 4 || x<1)
{
this.teamStatuss = x;
this.teamStatus = teamStatus.INELIGIBLE;
}
}
請發佈*短*,但完整的程序來演示問題。我懷疑你發佈的代碼很少有相關的 - 但它也不完整。 –
你可以發佈所有修改'Team.teamStatus'的代碼嗎? –
@Ankosh是否有'enum teamStatus'?另請注意,方法名稱應以小寫字母[a-z]開頭。將方法名從'TeamStatus'更改爲'setTeamStatus',並將'store.get(i).teamStatus = temp.teamStatus.PREPARING'更改爲'store.get(i).setTeamStatus(1)'。 –