Java Payroll ACME Project, Compiling problems - java

I have to create a program which has to include three or more classes including my Main class which will run the class simultaneously. 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. 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." 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));
to:
totalPay2 = totalHours * (employeeWages2.get(i - 1));

Related

How can I put an if statement inside of a if-else if statement

I am trying to make a salary calculator that if the applicant is under 18, they cannot receive overtime, because in the state I am in the maximum allowed for minors is 18 hours. I have it set where you cannot earn overtime until you reach 40 hours. Is there anything I can do for this?
import java.util.Scanner;
public class SalaryV2
{
public static void main(String[] args)
{
//Declare and initialize variables
double totalSalary;
boolean isOvertime;
Scanner in = new Scanner(System.in);
//Input
System.out.print("Please enter your name (first last): ");
String firstName = in.next();
String lastName = in.nextLine();
System.out.print("Please enter your age: ");
String customerAge = in.nextLine();
double age = Double.parseDouble(customerAge);
System.out.print("\nWhat is your hourly rate of pay: ");
String rateOfPay = in.nextLine();
double payRate = Double.parseDouble(rateOfPay);
System.out.print("\nHow many hours did you work: ");
String totalHoursWorked = in.nextLine();
double totalHours = Double.parseDouble(totalHoursWorked);
System.out.println();
//Processing
if(17 > age)
{
isOvertime = false;
totalSalary = totalHours * payRate;
}
else if(totalHours > 40)
{
if(totalHours > 40)
{
isOvertime = true;
totalSalary = 40 * payRate + (totalHours - 40) * payRate * 1.5;
}
else
{
isOvertime = false;
totalSalary = totalHours * payRate;
}
}
//Output
System.out.print("Employee Name: " + lastName + ", " + firstName\n);
System.out.print("Hours worked: " + totalHours);
System.out.println("\t\tOvertime: " + isOvertime +);
System.out.println("Salary: " + totalSalary);
}
}
Keep it simple, no need for else-if-if,
import java.util.Scanner;
public class SalaryV2{
public static void main(String[] args){
//Declare and initialize variables
double totalSalary= 0;
boolean isOvertime = false;
Scanner in = new Scanner(System.in);
//Input
System.out.print("Please enter your name (first last): ");
String firstName = in.next();
String lastName = in.nextLine();
System.out.print("Please enter your age: ");
String customerAge = in.nextLine();
double age = Double.parseDouble(customerAge);
System.out.print("\nWhat is your hourly rate of pay: ");
String rateOfPay = in.nextLine();
double payRate = Double.parseDouble(rateOfPay);
System.out.print("\nHow many hours did you work: ");
String totalHoursWorked = in.nextLine();
double totalHours = Double.parseDouble(totalHoursWorked);
System.out.println();
//Processing
if(age >= 18 && totalHours > 40) {
isOvertime = true;
totalSalary = 40 * payRate + (totalHours - 40) * payRate * 1.5;
}else{
isOvertime = false;
totalSalary = totalHours * payRate;
}
//Output
System.out.print("Employee Name: " + lastName + ", " + firstName +'\n' );
System.out.print("Hours worked: " + totalHours + '\n');
System.out.println("Overtime: " + isOvertime );
System.out.println("Salary: " + totalSalary);
}}
With the following input STDIN
firstname lastname
19
10
42
Output :
$javac SalaryV2.java
$java -Xmx128M -Xms16M SalaryV2
Please enter your name (first last): Please enter your age:
What is your hourly rate of pay:
How many hours did you work:
Employee Name: lastname, firstname
Hours worked: 42.0
Overtime: true
Salary: 430.0
If under 18 STDIN
firstname lastname
17
10
42
Output :
$javac SalaryV2.java
$java -Xmx128M -Xms16M SalaryV2
Please enter your name (first last): Please enter your age:
What is your hourly rate of pay:
How many hours did you work:
Employee Name: lastname, firstname
Hours worked: 42.0
Overtime: false
Salary: 420.0
Checked by executing the above code.
If you are a minor you cannot get additional pay for any overtime you work (strange as that may seem).
If you have less than 40 hours you cannot get pay for overtime (everybody knows the weird consequences of that...).
So you can only get paid for overtime if you are over 18 and have more than 40 hours.
if((18 <= age) && (totalHours > 40))
{
isOvertime = true;
totalSalary = 40 * payRate + (totalHours - 40) * payRate * 1.5;
} else
{
isOvertime = false;
totalSalary = totalHours * payRate;
}
I.e. I do not see the need for nested ifs.
I didn't understand very well your question, but here is something you can improve.
In the first if, you are not considering even 17 years old, you should put if(17 >= age) or if(18 > age).
Then, in the else if you put the same condition as the if below, so what you should do is:
else if(totalHours > 40)
{
isOvertime = true;
totalSalary = 40 * payRate + (totalHours - 40) * payRate * 1.5;
}
else
{
isOvertime = false;
totalSalary = totalHours * payRate;
}
And to make your code more efficient, you can put two conditions in one if.
if(18 > age && totalHours > 40)
{
isOvertime = false;
totalSalary = totalHours * payRate;
}
else
{
isOvertime = true;
totalSalary = 40 * payRate + (totalHours - 40) * payRate * 1.5;
}
I didn't check if the code actually works, but it should be fine

Java Tax & NI GUI Calculator

I'm trying to calculate a Tax and NI calculator. I managed to write the code for it but can't seem to get the GUI working. i have tried to implement many different examples but they seem to give out errors. I just want to keep it simple and i even tried message dialog and a normal GUI screen with a OK button
Code for Calculator: (User enters their income and it calculates the tax etc.)
package netincome;
import java.io.*;
public class NetIncome {
int pan;
String name;
double taxableincome;
double tax;
double taxpermonth;
double annualNIpayments;
double NIpermonth;
double netmonthlyincome;
void input() throws IOException {
InputStreamReader in = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(in);
System.out.println("Enter taxable income:");
taxableincome = Double.parseDouble(br.readLine());
}
void computeData() {
if (taxableincome <= 11000) {
tax = 0;
taxpermonth = tax/12;
annualNIpayments = 0 * 0.00;
NIpermonth = annualNIpayments/12;
netmonthlyincome = ((taxableincome - tax - annualNIpayments)/12);
} else if (taxableincome > 11001 && taxableincome <= 43000) {
tax = (taxableincome * 0.20);
taxpermonth = tax / 12;
annualNIpayments = taxableincome * 0.12;
NIpermonth = annualNIpayments / 12.0;
netmonthlyincome = ((taxableincome - tax - annualNIpayments)/12);
} else if (taxableincome > 43001 && taxableincome <= 150000) {
tax = (taxableincome * 0.40);
taxpermonth = tax / 12.0;
annualNIpayments = taxableincome * 0.02;
NIpermonth = annualNIpayments / 12.0;
netmonthlyincome = ((taxableincome - tax - annualNIpayments)/12);
} else if (taxableincome > 150001) {
tax = (taxableincome * 0.45);
taxpermonth = tax / 12.0;
annualNIpayments = taxableincome * 0.02;
NIpermonth = annualNIpayments / 12.0;
netmonthlyincome = ((taxableincome - tax - annualNIpayments)/12);
}
}
void displayData() {
System.out.println("Taxable Income =" + taxableincome);
System.out.println("Annual Tax Paid =" + tax);
System.out.println("Monthly Tax Paid ="+ taxpermonth);
System.out.println("Annual NI =" + annualNIpayments);
System.out.println("Monthly NI =" + NIpermonth);
System.out.println("Net Monthly Income =" + netmonthlyincome);
}
public static void main(String args[]) throws IOException {
NetIncome ob = new NetIncome();
ob.input();
ob.computeData();
ob.displayData();
}
}
For example i used this website to get the dialog but can't seem to make the if statement to work on it: Message Dialog Code
The other ones were a GUI screen.
Thanks in advance.
i know my code isn't amazing but i'm only a beginner.
A simple way of doing this is:
Replace
System.out.println("Enter taxable income:");
taxableincome = Double.parseDouble(br.readLine());
with:
String input = JOptionPane.showInputDialog(null, "Enter taxable income:");
taxableincome = Double.parseDouble(input);
And then the output (I'll let you finish the rest off)
Replace:
System.out.println("Taxable Income =" + taxableincome);
with:
JOptionPane.showMessageDialog(null, "Taxable Income = "+ taxableincome);

Getting "while expected" error in "do...while" loop

I keep getting this error and I am not stuck trying to fix it.
package bonuscalc;
import java.text.DecimalFormat;
import java.util.Scanner;
public class BonusCalc {
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
DecimalFormat formatter = new DecimalFormat("#0.00");
int Salary;
double NewSal, Comm;
double p1 = 0.1;
double p2 = 0.15;
double p3 = 0.2;
double p4 = 0.3;
System.out.println("Welcome to Bonus Calculator");
do{
System.out.print("Enter your Salary: ");
Salary = input.nextInt();
}While (Salary < 0)
if((Salary > 0) && (Salary <= 8000)){
Comm = (Salary * p1);
NewSal = Salary + Comm;
System.out.print("Your Commition is RM" + formatter.format(Comm));
System.out.println(" and your New Salary is RM" + formatter.format(NewSal));
}
else if((Salary > 8000) && (Salary <= 15000)){
Comm = (Salary * p2);
NewSal = Salary + Comm;
System.out.print("Your Commition is RM" + formatter.format(Comm));
System.out.println(" and your New Salary is RM" + formatter.format(NewSal));
}
else if((Salary > 15000) && (Salary <= 25000)){
Comm = (Salary * p3);
NewSal = Salary + Comm;
System.out.print("Your Commition is RM" + formatter.format(Comm));
System.out.println(" and your New Salary is RM" + formatter.format(NewSal));
}
else if(Salary > 25000){
Comm = (Salary * p4);
NewSal = Salary + Comm;
System.out.print("Your Commition is RM" + formatter.format(Comm));
System.out.println(" and your New Salary is RM" + formatter.format(NewSal));
}
else{
System.out.println("Input invalid. Renter Salary");
}
}
}
You have written While instead of while.
do {
...
} While (Salary < 0);
correct would be:
do {
...
} while (Salary < 0);
Hope this solves your problem.
Your do-while loop has an invalid syntax. Firstly, while is lowercase, thus While is incorrect. Moreover, you are missing a semicolon.
do {
System.out.print("Enter your Salary: ");
Salary = input.nextInt();
} while (Salary < 0);
On a side note, in Java variables usually start with lowercase letters. It is not a strict rule, but a convention that it is prudent to conform to.

How To Limit User Input In Java

The amount of investment must be positive and can be any value.
The period of investment is in years so should be positive.
The annual rate of interest can be between 0.25% to 14%.
import java.util.Scanner;
public class InterestCalculator{
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner input = new Scanner(System.in);
// Entering the interest rate
System.out.print("Please Enter the annual interest rate between 0.25 to 10 : ");
double annualInterestRate = input.nextDouble();
double monthlyInterestRate = annualInterestRate / 1200;
System.out.print("Enter number of years: ");
int numberOfYears = input.nextInt();
// Entering the amount earned
System.out.print("Enter Amount: ");
double Amountofinterest = input.nextDouble();
// Calculating
double moneyearned = Amountofinterest * monthlyInterestRate;
// Displaying the results
System.out.println("The money earned is $" +
(int) (moneyearned * 100) / 100.0);
int i;
for (i = 1; i <= numberOfYears * 12; i++) {
double Balance = Amountofinterest + moneyearned;
Amountofinterest = Balance;
monthlyInterestRate = moneyearned + 0.01;
System.out.println(i + "\t\t" + Amountofinterest
+ "\t\t" + monthlyInterestRate + "\t\t" + Balance);
}
}
}
I have made the basic program but, I don't know how to add restrictions.
Are you talking about this :
while(input.nextDouble()<0){
System.out.println("Please enter positive investment");
}
You can use loops that repeatedly ask for input until it's valid:
double annualInterestRate = 0;
while (annualInterestRate < 0.25 || annualInterestRate > 10){
System.out.print("Please Enter the annual interest rate between 0.25 to 10 : ");
annualInterestRate = input.nextDouble();
if (annualInterestRate < 0.25 || annualInterestRate > 10){
System.out.println("Please enter a value between 0.25 and 10");
}
}
//if you reach this point, input is valid because it is neither <0.25 or >10
You can do this for all values that need to meet certain criteria. Just make sure you initialize the variable before the loop and set it as an invalid value, otherwise the loop won't run.
Other variables:
int numberOfYears = -1; //or 0 is you don't allow 0 years
while (numberOfYears < 0){ //or <= 0 if you don't allow 0 years
System.out.print("Enter number of years: ");
numberOfYears = input.nextInt();
}
double Amountofinterest = -1; //or 0
while (Amountofinterest < 0){ //or <= 0
System.out.print("Enter Amount: ");
Amountofinterest = input.nextDouble();
}
Ok you could then use a while loop like this:
int numberOfYears = -1;
System.out.print( "Enter number of years: ");
while(numberOfYears < 0){
numberOfYears = input.nextInt();
}
I'd like to offer a more elegant way of getting data via CLI, where the risk of exception or any other input hazard is minimised.
I've written this function and think it may well cover the Integer, Double and String objects, but you may continue expanding it further:
public Object securedInput(String intro, String type, int maxLength)
{
//Apply Scanner
Scanner input = new Scanner(System.in);
//Show intro
if(intro != null)
System.out.print(intro+" ");
//Get user's input
String inStr = input.next(); //always get a string
//Enforce length
if((maxLength>0)&&(inStr.length() > maxLength))
inStr = inStr.substring(0, maxLength);
String result;
if(inStr == null || inStr.length() < 1)
return null;
switch (type)
{
case "int":
result = inStr.replaceAll("[^0-9]", "");
if(result.length() < 1 || result.length() < inStr.length())
return null;
else
return Integer.parseInt(result);
case "double":
result = inStr.replaceAll("[^0-9.]", "");
if(result.length() < 1 || result.length() < inStr.length())
return null;
else
return Double.parseDouble(result);
//break;
case "string":
result = inStr.replaceAll("[^a-zA-Z .-]", "");
if(result.length() < 1 || result.length() < inStr.length())
return null;
else
return result;
default:
return null;
}
}
Here,as you can see I first take the input as String, then clean it according to my need, and then try to convert it without the risk of getting any exception.
And if something is wrong you simply get a null.
This can be used like this:
Integer i = (Integer)securedInput("Enter an integer:","int", 3);
Double d = (Double)securedInput("Enter a double","double",4);
String s = (String)securedInput("Enter a string","string",2);
You can add further arguments, such as range, and forbidden characters and even output errors according to the problem.
Hope this had helped.

ArrayList out of Bounds Exception? PayRoll Class

I have a project in my programming class that has to give a PayRoll scenario which contains three classes including PayRoll, PayRollTester, and EmployeeRecord. My code compiles and prints the EmployeeRecord correctly but does not list the PayRoll correctly. Instead, I receive an error saying Error: Out of Bounds of ArrayList.
Payroll:
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Date;
// ...javadoc...
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 = 1;
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);
totalPay2 = 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);
totalPay2 = totalHours * (employeeWages2.get(i - 1)) + (overTime2 * 1.5);
totalPay.add(totalPay2);
hoursWorked = 0.0;
hoursWorked2 = 0.0;
}
else if(hoursWorked > 40 && hoursWorked2 <= 40 && hoursWorked2 > 0)
{
overTime = hoursWorked - 40;
totalHours = hoursWorked + hoursWorked2;
hours.add(totalHours);
totalPay2 = totalHours * (employeeWages2.get(i - 1)) + (overTime * 1.5);
totalPay.add(totalPay2);
hoursWorked = 0.0;
hoursWorked2 = 0.0;
}
else if(hoursWorked > 40 && hoursWorked2 > 40)
{
overTime = hoursWorked - 40;
overTime2 = hoursWorked2 - 40;
totalHours = hoursWorked + hoursWorked2;
hours.add(totalHours);
totalPay2 = totalHours * (employeeWages2.get(i - 1)) + (1.5 * (overTime + overTime2));
totalPay.add(totalPay2);
hoursWorked = 0.0;
hoursWorked2 = 0.0;
}
i = quit;
}
System.out.println();
System.out.println("Employee Number | Employee Name | Hours Worked | Total Pay");
for(int i = 0; i < e.getEmployeeNamesArrayList().size();)
{
System.out.println(String.format(employeeID, i + 1) + " | " + emID.get(i + 1) + " | " + hours.get(i + 1) + " | " + totalPay.get(i + 1));
}
}
}
EmployeeRecord:
import java.util.Scanner;
import java.util.ArrayList;
// ...javadoc...
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. Type 'Q Q' when you are done entering employee information.");
while(employeeFullName != "Q")
{
employeeFullName = input.next() + " " + input.next();
if(employeeFullName.equalsIgnoreCase("Q" + " " + "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;
}
}
PayrollTester:
import java.util.Scanner;
// ...javadoc...
public class PayrollTester
{
public static void main(String[] args)
{
Payroll employeeComplete = new Payroll();
employeeComplete.setEmployeePayroll();
}
}
ArrayList index starts from 0. since your for loop start i = 0, you cannot do (i+1) in accessing arrayList elements.
emID.get(i + 1)
and also the size of emID is always 0 because you have just create new Arraylist but not added any objects to that list.

Categories

Resources