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

时间:2015-04-21 21:29:01

标签: java object constructor

在我循环的最后一段代码中,我正在尝试访问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);
        }
    }
}

Team 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;
        }

    }

1 个答案:

答案 0 :(得分:1)

teams的类型是什么?如果团队是一个列表或集合,请检查您是否指定了泛型类型 - 即确保它是List<Team>Set<Team>而不仅仅是ListSet 。那么for each循环就是

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

并确保teamm的类型为Team