Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 类之间的数组?_Java_Arraylist - Fatal编程技术网

Java 类之间的数组?

Java 类之间的数组?,java,arraylist,Java,Arraylist,主类 package finalapp; import java.util.Scanner; /** * * @author bassammetwally */ public class FinalApp { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application

主类

package finalapp;
import java.util.Scanner;

/**
 *
 * @author bassammetwally
 */
public class FinalApp {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner input = new Scanner(System.in);
        Team tem = new Team();
        Tournament tour = new Tournament();
        System.out.print("Whats the tournament name?\n");
        tour.setTourName(input.next());
        System.out.print("Please enter the tournamen date\n");
        tour.setTourDate(input.next());
        System.out.print("Please enter the location\n");
        tour.setLocation(input.next());
        System.out.print("Please enter number of Software Stations\n");
        tour.setAvaliableHardwareIns(input.nextInt());
        System.out.print("Please enter number of Hardware Stations\n");
        tour.setAvaliableHardwareIns(input.nextInt());
        System.out.print("Please enter number of field testing");
        tour.setAvaliableFieldTesting(input.nextInt());
        System.out.print("Please enter max number of teams\n");
        tour.setMaxNumberOfTeams(input.nextInt());
        tour.tourStatSet(1);

        while (true)
        {
            int choice;
            choice = input.nextInt();
            if (choice == 1)
            {
                System.out.printf("Enter Team %s Names\n",tour.getMaxNumberOfTeams());
                for (int i = 0; i >= tour.getMaxNumberOfTeams();i++)
                {
                    System.out.print("Please Enter Team Name");
                    tour.addingTeam(input.next());
                    tem.teamStats(1);
                    tem.teamJudgeStat(1);
                    Have a PREPARING team turn the robot on 
                    (set the robot status to READY) to prepare for inspections        
                }
            }
            else if ( choice == 2)
            {
               System.out.print("Sending prepareing teams");
               //for (int a = 0; a >= tour.getTeamsChecked(); a++)
               {

               }

            }
    }


}
问题:

我正在做一个机器人竞赛模拟,我试图让主要的班级:

  • 添加团队,我已经这样做了
  • 更改阵列中每个团队的状态
但是我的主要想法是遍历
ArrayList
并更改其他类中的变量,但我不知道如何做


有没有更简单的方法可以做到这一点?

听上去,你应该能够使用简单的getter和setter来做你想做的事情


只需使用一个方法将所需的值设置到数组中,然后使用另一个方法获取数组或数组中的特定索引。这样,您可以在类之间设置和共享数组。

欢迎使用SO!如果可以,请减少链接代码的数量,以便只显示与您的问题最相关的代码。非常感谢你!但是如果有10个以上的团队,那么有一个接受团队名称并将其添加到另一个类中的ArrayList的方法不是很容易吗@您可以有一个方法,将团队数组列表传递到该方法中,该方法将自动将该数组列表添加到其他类的数组列表中