基本上,我的计划的重点是用户输入员工数量的工资单程序,然后用相同数量的员工完成指示员工类型的过程,然后继续输入员工基于类型。现在,我一次去一个小时,首先开始每小时一次。我设法得到我想要的输出,直到我最终完成while循环的条件继续输出结果表,但它不输出结果,只输出列标签。我决定使用for循环,以便它继续显示,直到它达到大于该数字的数字。我检查了我是否使用了正确的数组格式[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() );}
}
}
答案 0 :(得分:0)
在for循环中,你的情况是错误的。它应该是:
for (int e=0; e < size; e++)