Java 将字符串[]args值传递给另一个类

Java 将字符串[]args值传递给另一个类,java,string,variables,queue,args,Java,String,Variables,Queue,Args,我有一个命令行输入0 1 2,主要代码如下所示 public class AppleStoreRunner { public static void main(String [] args) { //maximum size of queue int qCapacity = Integer.parseInt(args[0]); //number of simulation hours int simHours = Inte

我有一个命令行输入0 1 2,主要代码如下所示

public class AppleStoreRunner {
   public static void main(String [] args) {

        //maximum size of queue
        int qCapacity = Integer.parseInt(args[0]);

        //number of simulation hours
        int simHours = Integer.parseInt(args[1]);

        //average number of customers per hour
        int custPerHour = Integer.parseInt(args[2]);

        AppleStore myStore = new AppleStore(qCapacity, simHours, custPerHour);

        //Run simulation
        myStore.simulation();
        myStore.displayAcceptedCustomers();
        myStore.displayServedCustomers();
        myStore.displayWaitingCustomers();
        myStore.displayTurnAwayCustomers();

    }
}
如何在下面的类中调用输入的命令行参数,以便在单独的扩展类中使用输入?下面的代码是我试图为3个输入的数字创建变量的类

public class AppleStore {

 int qCapacity;
 int simHours;
 int custPerHour;

/** Constructor 
* @param qCapacity The initial capacity of the queue to be used. 
* @param simHours The number of hours that the simulation should run. 
* @param custPerHour expected number of customers to arrive per hour. 
 */ 
     public AppleStore(int qCapacity, int simHours, int custPerHour) 

     {
         qCapacity = AppleStoreRunner.main(args);
     }
 /** 
     * This methods performs a simulation of a store operation using a queue and prints the statistics. 
     * For every minute, the simulator 1) checks if there are new customers arriving; 2) adds the new customer into the waiting line or else records the customer who chooses to leave; 3) continues to help the current customer if the current customer is not finished yet, or else get the next person in the waiting line. The simulator starts at minute 0, and repeats every minute until it finishes the requested simulation time.  
     */ 
     public void simulation( ) 
     {
     System.out.println( "Average Waiting Time" + );
     System.out.println( "Average Line Length" + );

     /** 
     *  print the info of all accepted customers 
     */ 
     }
      public void displayAcceptedCustomers() 
      {
          System.out.println("Customers accepted" + );

     /** 
     * print the info of all served customers 
     */ 
      }
      public void displayServedCustomers() 

      /** 
      * print the info of all waiting customers 
      */ 
      public void displayWaitingCustomers() 

     /** 
     * print the info of all turned away customers 
     */ 
     public void displayTurnAwayCustomers() 

}

因为你做了
applestoremystore=newapplestore(qCapacity,simHours,custPerHour)
public AppleStore(int qCapacity, int simHours, int custPerHour) 

{
    this.qCapacity = qCapacity;
    this.simHours = simHours;
    this.custPerHour = custPerHour;
}
当您将三个实例变量声明为包私有时,子类将自动看到这三个变量的存在

但是,如果您以某种方式使子类不受对超类(我的意思是,
AppleStore
)的更改的影响,我建议为这三个变量添加一些可以从子类调用的getter,例如:

int getQueueCapacity() {
    return this.qCapacity;
}

并将三个变量的访问级别更改为私有

因为你做了
applestoremystore=newapplestore(qCapacity,simHours,custPerHour)
public AppleStore(int qCapacity, int simHours, int custPerHour) 

{
    this.qCapacity = qCapacity;
    this.simHours = simHours;
    this.custPerHour = custPerHour;
}
当您将三个实例变量声明为包私有时,子类将自动看到这三个变量的存在

但是,如果您以某种方式使子类不受对超类(我的意思是,
AppleStore
)的更改的影响,我建议为这三个变量添加一些可以从子类调用的getter,例如:

int getQueueCapacity() {
    return this.qCapacity;
}

并将三个变量的访问级别更改为私有

您是否正在尝试创建一个无限递归程序?我不明白。您的
main
方法创建一个新的
AppleStore
,它调用构造函数,调用
main
,它创建一个新的
AppleStore
,它。。。如果你的目标是试图通过使苹果商店堆栈溢出来炸毁它,我怀疑这会起作用。:)您是否正在尝试创建一个无限递归程序?我不明白。您的
main
方法创建一个新的
AppleStore
,它调用构造函数,调用
main
,它创建一个新的
AppleStore
,它。。。如果你的目标是试图通过使苹果商店堆栈溢出来炸毁它,我怀疑这会起作用。:)非常感谢你。我以为我的构造器主要是私人的,所以我认为需要一个新的构造器。非常感谢。我认为我的构造函数基本上是私有的,因此假设需要一个新的构造函数。