【问题标题】:Displaying array values through object that references other methods not displaying with for loop通过引用其他不使用 for 循环显示的方法的对象显示数组值
【发布时间】:2014-12-03 04:19:35
【问题描述】:

基本上,我的程序的重点是一个工资单程序,用户输入员工数量,然后与相同数量的员工通过指示它是什么样的员工的过程,然后继续输入信息基于类型的员工。现在,我一次去一个,首先从每小时开始。我设法得到我想要的输出,直到我最终完成 while 循环的条件以继续并输出结果表,但它不输出结果,只输出列标签。我决定使用 for 循环,以便它继续显示,直到达到大于大小的数字。我检查了我是否为 array[e].method(); 使用了正确的格式;但到目前为止似乎还没有发现任何问题。

是否有可能是参数不匹配或滥用?

提前致谢。

  Scanner in = new Scanner(System.in);
  System.out.println("Welcome to the Company's Payroll System!");
  System.out.println("Please enter the amount of employees in the company.");
  int size = in.nextInt();
  Employee [] staff = new Employee [size];

  int i = 0;

  while (i != staff.length ) 
      {

      System.out.println("Enter employee type (Choose Hourly, Salary, or Manager)");
      System.out.println("Press 4 to exit.");
      String emptype = in.next();

     if (emptype.equalsIgnoreCase("Hourly")) 
     {
        System.out.println("First name:"); 
        String first = in.next();

        System.out.println("Last name:");
        String last = in.next();

        System.out.println("Employee ID (7 digits):");
        Float identification = in.nextFloat();

        System.out.println("Job Title:");
        String title = in.next();

        System.out.println("Amount employee makes per hour: ");
        double hour = in.nextDouble();

        staff [i] = new HourlyEmployee(first, last, identification, title, hour);

        i++;
     }

      }


       System.out.println("FIRST NAME \t LAST NAME \t ID \t JOB TITLE \t Weekly Salary");
       for (int e = 0; e > size; e++)
       {
       System.out.printf("%5d", staff[e].getfirstName() + staff[e].getlastName() + staff[e].getId() + staff[e].getTitle() + staff[e].weeklyPay() );}
      }

}

【问题讨论】:

    标签: java arrays for-loop polymorphism parameter-passing


    【解决方案1】:

    在 for 循环中,您的条件是错误的。应该是:

    for (int e=0; e < size; e++)
    

    【讨论】:

      猜你喜欢
      • 2021-12-27
      • 1970-01-01
      • 2018-10-27
      • 2015-08-10
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      • 2012-10-05
      相关资源
      最近更新 更多