I have tried to figure out how to implement the
java.text.DecimalFormat import, but I couldn't figure out the correct syntax to apply it to my numbers. This program is for an entry level programming class. The application require it actually be formatted, but I want to know how to anyway.
I have an employee ID number that I need formatted without any decimal places, the dollar amounts to have two decimals places, and the employee hours to only have decimal places.
Can anyone maybe explain the syntax for any particular variable I am using
Here's what I have:
import java.util.Scanner;
public class FigureWages {
public static void main(String[] args) {
double employeeNumber;
double payRate;
double wagesTotal; // Total wages of all employees
double amountEarned;
double hoursWorked;
double formTotal; //loop counter
String employeeTotalString;
double employeeTotal;
Scanner input = new Scanner(System.in);
do{
System.out.print("\n Please enter the total number of employees: ");
employeeTotalString = input.nextLine();
employeeTotal = Double.parseDouble(employeeTotalString);
}while (employeeTotal <= 0);// end do-while loop
for (formTotal = employeeTotal, amountEarned = 0, wagesTotal = 0; formTotal > 0; formTotal--, employeeTotal--) {
System.out.print("\n\n Please enter your employee number:");
employeeNumber = input.nextDouble();
System.out.print("\n Please enter your base rate of pay per hour: ");
payRate = input.nextDouble();
System.out.print("\n Please enter your number of hours worked: ");
hoursWorked = input.nextDouble();
//overtime calculations
if (hoursWorked <= 40){
amountEarned = payRate * hoursWorked;
wagesTotal += amountEarned;
}
else if (hoursWorked > 40 && hoursWorked <=60){
amountEarned = (40 * payRate) + ((hoursWorked - 40) * (payRate * 1.5));
wagesTotal += amountEarned;
}
else if (hoursWorked >= 60){
amountEarned = (40 * payRate) + ((hoursWorked - 40) * (payRate * 1.5)) + (hoursWorked * 2);
wagesTotal += amountEarned;
}
System.out.print("\n\n\tEmployee ID#: " + employeeNumber);
System.out.print("\n\tTotal hours worked: " + hoursWorked);
System.out.print("\n\tPay rate: "+ payRate + " (per hour)");
System.out.print("\n\tTotal wages earned by employee: " + "$" + amountEarned + "\n\n\n");
}// end for loop
System.out.print("\n\t Total wages earned by all employees: " + "$" + wagesTotal + "\n\n\n");
}
}
Thanks