员工薪资总薪水表

时间:2018-10-24 05:28:54

标签: javascript arrays

我的任务是创建一个代码,该代码将计算员工的总薪资,且其小时薪不能低于$ 8。我不确定为什么我的代码将无法运行,在编译时不会显示错误。

public static void main(String[] args) {

    Scanner key = new Scanner(System.in);

    int numEmployees = key.nextInt();
    int employeeName[] = new int[numEmployees];
    int hoursWorked[] = new int[numEmployees];
    int hourlyWage[] = new int[numEmployees];
    int grossWages[] = new int[numEmployees];

    System.out.println("Enter the number of employess whose gross wages"
            + " you wish to calculate:");
    //user enter employee name

    for(int i = 1; i < employeeName.length; i++)
    {
        System.out.println("Enter name of employee " + i+ ":");
        employeeName[i]= key.nextInt();
        i++;
    }

    //user enters number of hours
    //System.out.println("How many hours did" + employeeName[i] + " work this week?");

    for(int i = 0; i< numEmployees; i++)
    {
        System.out.print("How many hours did" + employeeName[i] + " work this week?");
        hoursWorked[i] = key.nextInt();

        //get the hourly pay rate
        System.out.print("What is" + employeeName[i] + " hourly wage?");
        //hourlyWage = key.nextInt();

        grossWages[i] = hoursWorked[i] * hourlyWage[i];
    }
    //displays wages
    System.out.println("The hours and pay rates you entered are:");

    for(int i = 0; i < numEmployees; i++)
    {
        //hourlyWage = key.nextInt();
        System.out.printf("The total wages for Employee #%d is $%.2f\n", employeeName[i], hourlyWage);
    }

    //System.out.print("");
    //System.out.print("Name     Hours Worked     Hourly Pay Rate     Gross Wages Earned");
    //System.out.println(employeeName + "     " + hoursWorked + "     " + hourlyWage + "     " + grossWages);

} }

2 个答案:

答案 0 :(得分:0)

1)在接受输入之前提示

System.out.println("Enter the number of employess whose gross wages"
        + " you wish to calculate:");

然后

int numEmployees = key.nextInt();

2)从零开始循环

for(int i = 1; i < employeeName.length; i++)

3)取消注释

//hourlyWage = key.nextInt();

修改

为什么员工姓名为int

答案 1 :(得分:0)

public static void main(String [] args){

Scanner key = new Scanner(System.in);

int numEmployees = key.nextInt();
int employeeName[] = new int[numEmployees];
int hoursWorked[] = new int[numEmployees];
int hourlyWage[] = new int[numEmployees];
int grossWages[] = new int[numEmployees];

System.out.println("Enter the number of employess whose gross wages"
        + " you wish to calculate:");
//user enter employee name

for(int i = 1; i < employeeName.length; i++)
{
    System.out.println("Enter name of employee " + i+ ":");
    employeeName[i]= key.nextInt();
    i++;
}

//user enters number of hours
//System.out.println("How many hours did" + employeeName[i] + " work this week?");

for(int i = 0; i< numEmployees; i++)
{
    System.out.print("How many hours did" + employeeName[i] + " work this week?");
    hoursWorked[i] = key.nextInt();

    //get the hourly pay rate
    System.out.print("What is" + employeeName[i] + " hourly wage?");
    hourlyWage[i] = key.nextInt();

    grossWages[i] = hoursWorked[i] * hourlyWage[i];
}
//displays wages
System.out.println("The hours and pay rates you entered are:");

for(int i = 0; i < numEmployees; i++)
{
    //hourlyWage = key.nextInt();
    System.out.printf("The total wages for Employee #%d is $%.2f\n", employeeName[i], hourlyWage[i]);
}

//System.out.print("");
//System.out.print("Name     Hours Worked     Hourly Pay Rate     Gross Wages Earned");
//System.out.println(employeeName + "     " + hoursWorked + "     " + hourlyWage + "     " + grossWages);

}}