I am trying to get my output to match the output shown in the image. I think my variable values are getting crossed and giving me the incorrect output. also if you have any tips on how I can better organize my code I'd greatly appreciate it! Thank you! import java.util.Scanner; public class Program4 { //*************************************************************** // // Method: main // // Description: The main method of the program // // Parameters: String array // // Returns: N/A // //************************************************************** //start of main() method public static void main(String[] args) { Scanner input = new Scanner(System.in); //get employee info System.out.print("Enter your ID number: "); int employeeID = input.nextInt(); System.out.print("Enter you Payrate: "); double hourlyPay = input.nextDouble(); System.out.print("Enter your hours worked: "); double hoursWorked = input.nextDouble(); //Calculate Regular and overtime pay double regularHoursPay; double overTimeHoursPay = 0; if (hoursWorked <= 40){ regularHoursPay = hoursWorked * hourlyPay; } else { overTimeHoursPay = hoursWorked - 40; regularHoursPay = overTimeHoursPay * (hourlyPay * 1.5); } //Calculate gross pay double grossPay; double overTimeHours = 0; if(hoursWorked <= 40) { grossPay = hoursWorked * hourlyPay; } else { overTimeHours = hoursWorked - 40; grossPay = hourlyPay * 40 + overTimeHours * hourlyPay * 1.5; } //Calculate deductions double incomeTax = 0; double parkingCharge = 35; double totalDeduction = (incomeTax + parkingCharge); if(grossPay > 750) { incomeTax = grossPay * .1275 ; } //Calculate net pay double netPay = grossPay - totalDeduction; //Display employee results System.out.println("Program 4 "); System.out.printf("ID Number: %d%n", employeeID); System.out.printf("Pay Rate: %.2f%n", hourlyPay); System.out.printf("Regular Hours: %.2f%n", hoursWorked); System.out.printf("Overtime Hours: %.2f%n", overTimeHours); System.out.printf("Total Hours: %.2f%n", overTimeHours + hoursWorked); System.out.printf("Regular Pay: %.2f%n", regularHoursPay); System.out.printf("Overtime Pay: %.2f%n", overTimeHoursPay); System.out.printf("Gross Pay: %.2f%n", grossPay); System.out.printf("Tax: %.2f%n", incomeTax); System.out.printf("Deductions: %.2f%n", totalDeduction); System.out.printf("Net Pay: %.2f%n", netPay); }
I am trying to get my output to match the output shown in the image. I think my variable values are getting crossed and giving me the incorrect output. also if you have any tips on how I can better organize my code I'd greatly appreciate it! Thank you!
import java.util.Scanner;
public class Program4 {
//***************************************************************
//
// Method: main
//
// Description: The main method of the program
//
// Parameters: String array
//
// Returns: N/A
//
//**************************************************************
//start of main() method
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
//get employee info
System.out.print("Enter your ID number: ");
int employeeID = input.nextInt();
System.out.print("Enter you Payrate: ");
double hourlyPay = input.nextDouble();
System.out.print("Enter your hours worked: ");
double hoursWorked = input.nextDouble();
//Calculate Regular and overtime pay
double regularHoursPay;
double overTimeHoursPay = 0;
if (hoursWorked <= 40){
regularHoursPay = hoursWorked * hourlyPay;
}
else {
overTimeHoursPay = hoursWorked - 40;
regularHoursPay = overTimeHoursPay * (hourlyPay * 1.5);
}
//Calculate gross pay
double grossPay;
double overTimeHours = 0;
if(hoursWorked <= 40) {
grossPay = hoursWorked * hourlyPay;
}
else {
overTimeHours = hoursWorked - 40;
grossPay = hourlyPay * 40 + overTimeHours * hourlyPay * 1.5;
}
//Calculate deductions
double incomeTax = 0;
double parkingCharge = 35;
double totalDeduction = (incomeTax + parkingCharge);
if(grossPay > 750) {
incomeTax = grossPay * .1275 ;
}
//Calculate net pay
double netPay = grossPay - totalDeduction;
//Display employee results
System.out.println("Program 4 ");
System.out.printf("ID Number: %d%n", employeeID);
System.out.printf("Pay Rate: %.2f%n", hourlyPay);
System.out.printf("Regular Hours: %.2f%n", hoursWorked);
System.out.printf("Overtime Hours: %.2f%n", overTimeHours);
System.out.printf("Total Hours: %.2f%n", overTimeHours + hoursWorked);
System.out.printf("Regular Pay: %.2f%n", regularHoursPay);
System.out.printf("Overtime Pay: %.2f%n", overTimeHoursPay);
System.out.printf("Gross Pay: %.2f%n", grossPay);
System.out.printf("Tax: %.2f%n", incomeTax);
System.out.printf("Deductions: %.2f%n", totalDeduction);
System.out.printf("Net Pay: %.2f%n", netPay);
}
![Name:
Instructor
Course: ITSE 2321 Object-Oriented Programming (Java)
Program: Four
This program computes an employee's gross, net, and overtime pay.
Enter your ID Number: 1001
Enter your pay rate: 12.50
Enter your hours worked: 36
Program 4
ID Number:
Pay Rate:
Regular Hours:
Overtime Hours:
Total Hours:
Regular Pay:
Overtime Pay:
Gross Pay:
Tax:
Deductions:
Net Pay:
1001
12.50
36.00
0.00
36.00
450.00
0.00
450.00
0.00
35.00
415.00](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F0085203e-d8e8-4049-b5a7-9027363de512%2F773514af-2350-43f1-9b21-685b54259a18%2Fb25ti95_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 5 steps with 3 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)