首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用对象内部的一些属性来使用它们?

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

Stack Overflow用户
提问于 2015-04-22 05:29:01
回答 1查看 37关注 0票数 0

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

Teamm.Stattt是另一个类中的一个整数,该类定义机器人(对象)是否准备就绪或是否通过了检查(枚举)。

我是不是漏掉了什么?语法还是逻辑?

请随时批评我的编程技巧,但仍在学习中,非常感谢!

代码语言:javascript
复制
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);
        }
    }
}

Team Class的第一部分,包括while循环;

代码语言:javascript
复制
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;
        }

    }
EN

回答 1

Stack Overflow用户

发布于 2015-04-22 05:51:11

teams的类型是什么?如果teams是list或set,请检查您是否指定了泛型类型-即确保它是List<Team>Set<Team>,而不仅仅是ListSet。那么for each循环将是

代码语言:javascript
复制
for (Team team : teams) {
    if (teamm.teamStattt == 1)
    {
        robb.Robot(teamWork , 1);
    }
}

并确保teamm的类型为Team

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29783468

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档