Question
Here is my code. Please adjust it using the directions below, thank you!! import java.util.Scanner; import java.util.Calendar; public class OlokoV003PA1 { public static void main(String[]
Here is my code. Please adjust it using the directions below, thank you!!
import java.util.Scanner;
import java.util.Calendar;
public class OlokoV003PA1
{
public static void main(String[] args)
{
String first = "";
String last = "";
char cont = ' ';
int hoursWorked = 0;
int trigger = 1;
double payRate = 0;
double grossPay = 0;
double retire401k = 0;
double percent401k = 0;
double grossPayTotal = 0;
double total401k = 0;
Scanner input = new Scanner(System.in);
Calendar dateTime = Calendar.getInstance();
String payrollExpense = String.format("WEEKLY HOURLY EMPLOYEE PAYROLL"
+ "%n%nDate: %tD"
+ "%nTime: %tr"
+ "%n%n%56S %21S", dateTime, dateTime, "GROSS PAY", "401K");
System.out.printf("%nWEEKLY HOURLY PAYROLL SYSTEM%n%nContinue? Enter 'Y' or 'N':");
cont = input.nextLine().charAt(0);
if(Character.toUpperCase(cont) == 'N')
{
System.out.printf("%nExiting Weekly Hourly Payroll System.");
}
while(Character.toUpperCase(cont) == 'Y')
{
System.out.printf("%nPlease enter the employee's first name followed by the "
+ "enter key along with their last name.%n");
first = input.next();
last = input.next();
System.out.printf("%nFirst Name: %s%nLast Name: %s%n", first, last);
System.out.printf("%nEnter the number of hours worked for %s %s: ", first, last);
hoursWorked = input.nextInt();
input.nextLine();
while(hoursWorked > 40 || hoursWorked
{
if(hoursWorked > 40)
{
System.out.printf("%nHours worked cannot EXCEED 40.%nPlease re-enter:");
}
if(hoursWorked
{
System.out.printf("%nHours worked cannot be LESS than 5.%nPlease re-enter: ");
}
hoursWorked = input.nextInt();
input.nextLine();
}
System.out.printf("%nEnter the employee's hourly pay rate: ");
payRate = input.nextDouble();
input.nextLine();
while(payRate 15)
{
if(payRate
{
System.out.printf("%nHourly pay cannot be LESS than $7.25.%nPlease re-enter: ");
}
if(payRate > 15)
{
System.out.printf("%nHourly pay cannot EXCEED $15.00.%nPlease re-enter: ");
}
payRate = input.nextDouble();
input.nextLine();
}
grossPay = hoursWorked * payRate;
grossPayTotal += grossPay;
System.out.printf("%nEnter the employee's 401K contribution as a percentage of salary (not to EXCEED 10%%): ");
percent401k = input.nextDouble();
while(percent401k > 10)
{
System.out.printf("%nContribution cannot EXCEED 10%%. Please re-enter: ");
percent401k = input.nextDouble();
input.nextLine();
}
retire401k = percent401k/100 * grossPay;
total401k = total401k + retire401k;
if(trigger == 1)
{
payrollExpense += String.format("%n%-26s %7s$%,15.2f%9s$%,13.2f",
first + " " + last, " ", grossPay, " ", retire401k);
trigger = 0;
}
else
{
payrollExpense += String.format("%n%-24s %9s %,15.2f %9s %,12.2f",
first + " " + last, " ", grossPay, " ", retire401k);
}
input.nextLine();
System.out.printf("%nWould you like to enter another employee? Enter 'Y' or 'N': ");
cont = input.next().charAt(0);
if (Character.toUpperCase(cont)== 'N')
{
payrollExpense += String.format("%n%n%-21s TOTALS %7s $%, 13.2f %7s $%,11.2f", " ", " ",
grossPayTotal, " ", total401k);
System.out.printf("%n%n%s", payrollExpense);
}
} // END while
} // End main()
} // End application class
PROGRAM INSTRUCTIONS: Create a program that produces a payroll expense report. Use print with format specifiers where needed. Don't forget to insert the exit statement at the end of main() The prompts and the final output show you the logical progression of your code and give you an idea as to where to place your code. 1. Program Logic: No plan for this PA a. The prompts (to return press Alt then left arrow) tell you what input variables you will need O2017 Linda Shepherd b. The final output specifications will tell you the type of calculations you will need (if any) and whether you will need to declare additional variables. c. The sample output will tell you the order of logic for your code 2. Logical Control Structures From PA1 a. Declare a payroll expense variable and initialize it with header, date, and time lines String payrollExpense String.format("WEEKLY HOURLY EMPLOYEE PAYROLL "%n%nDate: %tD" "%nTime: %tr'' "%n%n%56S %23S", dateTime, dateTime, "GROSS PAY", "401K"); b. Use if to determine when to print the exit message (to return press Alt then left arrow) c. Use a while loop to process payroll data for multiple employees. Use a sentinel-control variable. Prompts 2-6 are within this while-loop. Use nested whiles to determine the validity of hoursWorked, payRate, and 401k percentage 1) Use nested ifs to determine which error message/re-prompt to print ii. Use nested ifelse to determine the printing of the sign and adding an employee's payroll data to payrollExpense. iii. Use nested if to determine when to print the final output that is in payrollExpense d. Use print with format specifiers where needed. e. CODE FOR PROPER FINAL OUTPUT ALIGNMENT & JUSTIFICATION: where payrollExpense is the String variable you've already declared and populated with the header information. Each employee's payroll data will be added to this variable. Examine the actual Java code below and note the use of fields with different sizes to right and left justify so the output can be aligned according to the final output specifications. Note the use of to add to what is already in the payrollExpense variable
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started