Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Postgresql 16 Administration Cookbook Solve Real World Database Administration Challenges With 180+ Practical Recipes And Best Practices

Authors: Gianni Ciolli ,Boriss Mejias ,Jimmy Angelakos ,Vibhor Kumar ,Simon Riggs

1st Edition

1835460585, 978-1835460580

More Books

Students also viewed these Databases questions

Question

1. Discuss the four components of language.

Answered: 1 week ago

Question

a. How many different groups were represented?

Answered: 1 week ago