简体   繁体   English

Java Payroll ACME 项目,编译问题

[英]Java Payroll ACME Project, Compiling problems

I have to create a program which has to include three or more classes including my Main class which will run the class simultaneously.我必须创建一个程序,该程序必须包含三个或更多类,包括我的 Main 类,它将同时运行该类。 Right now, I have a class called EmployeeRecord, which will create arrays for the employees information (employee full name, tax ID, employee ID, and their wage), and another class called Payroll, which is the class I am having the most trouble.现在,我有一个名为 EmployeeRecord 的类,它将为员工信息(员工全名、税号、员工 ID 和他们的工资)创建数组,以及另一个名为 Payroll 的类,这是我遇到的最麻烦的类. In my if and else if statements, I am getting an error when trying to compile stating "incompatible types: double cannot be converted to java.util.ArrayList."在我的 if 和 else if 语句中,我在尝试编译时收到错误,指出“不兼容的类型:double 无法转换为 java.util.ArrayList”。 I cannot quite understand or find a fix to solve the problem.我无法完全理解或找到解决问题的方法。 I have posted my two classes for you.我已经为你发布了我的两个课程。 Thanks.谢谢。

import java.util.Scanner;
import java.util.ArrayList;
import java.util.Date;

/**
 * 
 * @Lab Three
 * @author Joseph Malachosky 
 * @version 9/14/2015
 */
public class Payroll
{
//ArrayLists that will use methods from EmployeeRecords.
ArrayList<String> employeeNames2;
ArrayList<Double> employeeWages2;

ArrayList<Integer> emID = new ArrayList<Integer>();
ArrayList<Double> hours = new ArrayList<Double>();
ArrayList<Double> totalPay = new ArrayList<Double>();
//Creating the hours and wages variables.
private double hoursWorked = 0.0;
private double hoursWorked2 = 0.0;
private int weeks = 0;
private String employeeID = "%03d";
private int quit = 1000;
private int i = 0;

Scanner input = new Scanner(System.in);

public void setEmployeePayroll()
{
    // Constructs a new EmployeeRecord.
    EmployeeRecord e = new EmployeeRecord();
    e.setEmployeeInfo();

    employeeNames2 = e.getEmployeeNamesArrayList();
    employeeWages2 = e.getWageArrayList();

    // Local variables used in setEmployeePayroll.
    double totalPay2 = 0.0;
    double totalHours = 0.0;
    double overTime = 0.0;
    double overTime2 = 0.0;

    System.out.println("Please enter ACME employee ID, the week they worked (1 or 2), and the number of hours worked. This information should be entered in the order the names were entered. Enter 0 when you are done inputing information.");

    while(quit != 0)
    {
        quit = input.nextInt();
        if(quit == 0)
        {
            break;
        }

        weeks = input.nextInt();

        if(weeks == 1)
        {
            hoursWorked = input.nextDouble();
        }
        else if(weeks == 2)
        {
            hoursWorked2 = input.nextDouble();
        }

        /*
         * I am checking to see if the employee is going to be paid for overtime and also calculating the pay for both weeks.
         * 1) My first if statement indicates whether or not the employee worked over 40 in week one and week two.
         * 2) My first else if statement indicates whether the employee works more than 40 hours in week two but not week one.
         * 3) My second else if statement indicates whether the employee works more than 40 hours in week one but not in week two.
         * 3) My third else if statement finally indicates that the employee worked over 40 hours in both week one and two.
         */
        if(hoursWorked > 0 && hoursWorked <= 40 && hoursWorked2 > 0 && hoursWorked2 <= 40)
        {
            totalHours = hoursWorked + hoursWorked2;
            hours.add(totalHours);
            totalPay = totalHours * (employeeWages2.get(i - 1));
            totalPay.add(totalPay2);
            hoursWorked = 0.0;
            hoursWorked2 = 0.0;
        }
        else if(hoursWorked2 > 40 && hoursWorked > 0 && hoursWorked <= 40)
        {
            overTime2 = hoursWorked2 - 40;
            totalHours = hoursWorked + hoursWorked2;
            hours.add(totalHours);
            totalPay = totalHours * (employeeWages.get(i - 1)) + (overTime2 * 1.5);
            tPay.add(totalPay);
            hoursWorked = 0.0;
            hoursWorked2 = 0.0;
        }
        else if(hoursWorked > 40 && hoursWorked2 <= 40 && hoursWorked2 > 0)
        {
            overTime = hoursWorked - 40;
            totalHours = hoursWorked + hoursWorked2;
            hours.add(totalHours);
            totalPay = totalHours * (employeeWages.get(i - 1)) + (overTime * 1.5);
            tPay.add(totalPay);
            hoursWorked = 0.0;
            hoursWorked2 = 0.0;
        }
        else if(hoursWorked > 40 && hoursWorked2 > 40)
        {
            overTime = hoursWorked - 40;
            overTime2 = hoursWorked2 - 40;
            totalHours = hoursWorked + hoursWorked2;
            hours.add(totalHours);
            totalPay = totalHours * (employeeWages.get(i - 1)) + (1.5 * (overTime + overTime2));
            tPay.add(totalPay);
            hoursWorked = 0.0;
            hoursWorked2 = 0.0;
        }

        i = terminate;
    }
    System.out.println();
    System.out.println("Employee Number  |  Employee Name    |  Hours Worked  |  Total Pay");
    for(int i = 1; i <= e.getEmployeeNamesArrayList().size(); i++)
    {
        System.out.println(String.format(employeeID, i) + "              | " + emID.get(i - 1) + "        | " + hours.get(i - 1) + "           | " + totalPay.get(i - 1));
    }
}

} }

import java.util.Scanner;
import java.util.ArrayList;
/**
 * Creating the objects and getMethods for each item that is stored in EmployeeRecord.
 * @Lab Three
 * @author Joseph Malachosky 
 * @version 9/14/2015
 */
public class EmployeeRecord
 {
/*
 * Creating the array and instance variables for EmployeeRecord consisting
 * of TaxID numbers, Employee Names, Wages, Employee ID numbers and hours worked.
 */
ArrayList<String> employeeNames = new ArrayList<String>();
ArrayList<String> taxIDList = new ArrayList<String>();
ArrayList<Double> employeeWages = new ArrayList<Double>();

Scanner input = new Scanner(System.in);

private String employeeID = "%03d";
private String employeeFullName = " ";
private String taxID = " ";
private double wage = 0.0;
//Adding employees.
public void setEmployeeInfo()
{
    System.out.println("Please enter the full names of each ACME employee, their employee tax ID, and their employee wage rate. Press Q when you are done entering employee information.");

    while(employeeFullName != "Q")
    {
            employeeFullName = input.next();
            if(employeeFullName == "Q")
            {
            break;
            }
            taxID = input.next();
            wage = input.nextDouble();

            employeeNames.add(employeeFullName);
            taxIDList.add(taxID);
            employeeWages.add(wage);

            System.out.println("Employee ID  |  Employee Name        |  Tax ID          |  Wage");
            for(int i = 1; i <= employeeNames.size(); i++)
            {
                System.out.printf(String.format(employeeID, i) + "          | " + employeeNames.get(i - 1) + "              | " + taxIDList.get(i - 1) + "          | " + "%1.2f",employeeWages.get(i - 1));
                System.out.println();
            }
    }
}

/**
 * Creating a method that returns the employee ArrayList employeeName.
 */
public ArrayList<String> getEmployeeNamesArrayList()
{
    return employeeNames;
}

/**
 * Creating a method that returns the employee's Tax ID ArrayList taxIDList.
 */
public ArrayList<String> getTaxIdsArrayList()
{
    return taxIDList;
}

/**
 * Creating a method that returns the wages ArrayList 
 */
public ArrayList<Double> getWageArrayList()
{
    return employeeWages;
}

} }

You have你有

 ArrayList<Double> totalPay = new ArrayList<Double>();

and then:进而:

 totalPay = totalHours * (employeeWages2.get(i - 1));

Does your compiler not tell you the line number?你的编译器没有告诉你行号吗?

i've found your mistake.我发现了你的错误。

change:改变:

totalPay = totalHours * (employeeWages2.get(i - 1)); totalPay = totalHours * (employeeWages2.get(i - 1));

to:到:

totalPay2 = totalHours * (employeeWages2.get(i - 1)); totalPay2 = totalHours * (employeeWages2.get(i - 1));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM