gpt4 book ai didi

java - 如何使用对象内部的一些属性来使用它们?

转载 作者:行者123 更新时间:2023-12-01 11:38:15 25 4
gpt4 key购买 nike

在 while 循环中的最后一个代码块中,我试图访问由 Team teamWork = new Team(....) 创建的每个对象,但由于某种原因它说不能找到符号。

Teamm.Stattt 是另一个类中的一个 int,它定义机器人(对象)是否准备好或通过检查(枚举)。

我有什么遗漏的吗?语法还是逻辑?

请随意批评我的编码技能,我仍在学习中,因此不胜感激!

for (int x = 1; x<=2; x++)
{
String teamName, sponsoringSchool, financialSponsor;
int noOfTeamMem, Teamnumber;
tour.Judging(); // how to assign?
System.out.print("Please enter Team Name\n");
teamName = input.next();
System.out.print("Please Enter Sponoring School?\n");
sponsoringSchool = input.next();
System.out.print("Please Enter Financial Sponsor\n");
financialSponsor = input.next();
System.out.print("Please Enter no of team Mem\n");
noOfTeamMem = input.nextInt();
System.out.print("please enter team number\n");
Teamnumber = input.nextInt();

Team teamWork = new Team(teamName, 1, 1, x ,noOfTeamMem, sponsoringSchool , financialSponsor);
Robot Rob = new Robot(teamWork);
for (int i = 1 ; i <= noOfTeamMem ; i++)
{
System.out.print("Please Enter first name ?\n");
String firstName = input.next();
System.out.print("please Enter Last Name\n");
String lastName = input.next();
System.out.print("Please Enter Email");
String email = input.next();
Person person = new Person(teamWork, firstName,lastName,email);
}
teams.add(teamWork);

}

while (true)
{

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");
int choice;
choice = input.nextInt();
if (choice == 1)
{
for (Object team : teams) {
if (teamm.teamStattt == 1)
{
robb.Robot(teamWork , 1);
}
}
}

团队类(class)的第一部分,包括 while 循环;

public class Team {
public String teamName;
public int teamNumber;
public String robotDesc;
public int noOfTeamMem;
ArrayList teamMem = new ArrayList();
public String sponsoringSchool;
public String financialSponsor;
public teamJudgeStat judgeing;
public String judgingLocation;
public int teamJudgee;
public int teamStattt;
private teamJudgeStat teamJudge;
private teamStat teamStatus;
private teamJudgeStat teamJudgeStatus;
public String teamJudginStatus; // ENUMERATED!!!
public int totalRankingPoints;
public int totalQualifyingPoints;
public int totalJudgingPoints;
Random gener = new Random();

public Team(String teamName,int teamStatus,int teamJudgeStatus, int Teamnumber, int noOfTeamMem, String sponsoringSchool, String financialSponsor) {
this.teamName = teamName;
this.teamNumber = Teamnumber;
this.teamJudgee = teamJudgeStatus;
this.noOfTeamMem = noOfTeamMem;
this.sponsoringSchool = sponsoringSchool;
this.financialSponsor = financialSponsor;
this.teamStattt = teamStatus;
}
public Team()
{

}
public void teamStats()
{
if (teamStattt == 1)
{
teamStatus= teamStat.PREPARING;
}
else if ( teamStattt == 2 )
{
teamStatus = teamStat.PASSED_INSPECTION;
}
else if (teamStattt == 3)
{
teamStatus = teamStat.PLAYED5_MATCHES;
}
else if (teamStattt==4)
{
teamStatus = teamStat.INELIGIBLE;
}

}

最佳答案

teams 的类型是什么?如果 team 是列表或集合,请检查您是否已指定泛型类型 - 即确保它是 List<Team>Set<Team>而不仅仅是ListSet 。那么 foreach 循环将是

for (Team team : teams) {
if (teamm.teamStattt == 1)
{
robb.Robot(teamWork , 1);
}
}

并确保 teamm 的类型为 Team .

关于java - 如何使用对象内部的一些属性来使用它们?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29783468/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com