Please write a simple JAVA code for a paystub following the objectives. Summary
ID: 3784475 • Letter: P
Question
Please write a simple JAVA code for a paystub following the objectives. Summary You've calculated gross income and created a simple paystub. However, all such tools are useless without the ability to entertime on a weekdy basis for proper timekeeping purposes. Hw2 assumed two-week period between paystubs, but it only counted hours worked beyond 80hours as overtime. However, this means that if an employee worked 60 hours one week and only20 the next, that employee will not get any overtime hours at all. Let's fix thisproblem on this homework Estimated Work Needed testing commenting, and cleanuplin less than 200 lines of code. In other words, you should expect to spend between 13Sto450 minutesworkingon this assignment. If you've spent more than 75 hours working on this assignment then you are likely struggling with scope and/or loops and should re-read the lecture slidesland attempt the exercises withini, seek help from your fellow classmates,myself, your lab instructor, QSC tutor, as well as online resources Skills Expected All the skills from previous Assignments Scopelaass Member Variables Loops Assignment Description write program that does the following fi Point Have the insurance Deductions" MS250 stored in a Point Ask the user for the following: Provide the following "main menu to the user (create a method for each of the choices: (I point Enter Hours Worked (1 point Display Summary (1 point Print Paystub (End Program (2points) Keep presenting the menu to the user until the user asks to print apaystub. For Enter Hours Worked Point Ask the user to enter hours worked on a weeldybasis. Begin with week1 1 point Be sure to check for valid values IWhat are valid values? What should you do for invalid values? 1 point) Display summary of regular and overtime hours recorded so far. points) Ask the userif there are more weeks to be entered. i Point) Continue looping if there are more weeksto beentered Return to "main menu" otherwise. For Display Summary (u point Display regular and overtime hoursrecorded so far and return to "main menu" For Print Poystub (End Progrom) Essentially print a paystub as in HW2 (1 point Calla method to print a header (MUST pass frst name and last name into method and use it) (iPoint Print out Regular Pay" (in the form of xregular hours $15 J (lpoint Print out "overtime Pay lim the form ofx Calculate and print Deductions asa point Medical and Dental Insurance: S2S for every week entered. Use defined above for fullpoints. i Point) Federal Taxes 30 of remaining income after Medical and Dental pointi Calculate and print Takehome Income" "Regular Pay "overtime Pay "Medical and Dental Insurance -"Federal Taxes" Optional Challenges lungradedl. Track every weekly hours recorded and display it when DisplaySummary iscaled. Allow user to edit the weekly hours they recorded.Explanation / Answer
// Paystub.java
import java.util.Scanner;
public class Paystub
{
static int insuranceDeduction = 25;
static int totalHours = 0;
static int regularHours = 0;
static int overtimeHours = 0;
static int week = 1;
public static int mainMenu()
{
System.out.println(" --------------Main Menu----------------");
System.out.print("1. Enter Hours Worked 2. Display Summary 3. Print Paystub (End program) Please choose from the above options: ");
Scanner keyboard = new Scanner (System.in);
int choice = keyboard.nextInt();
return choice;
}
public static void header(String firstName, String lastName)
{
System.out.println(" ************************************");
System.out.println("Paystub for " + lastName + ", " + firstName);
System.out.println("************************************ ");
}
public static void inputHours()
{
String choice = "y";
while(true)
{
System.out.println(" -------------Entering Hours----------------");
Scanner keyboard = new Scanner (System.in);
System.out.print("How many hours did you work on week " + (week) + ": ");
int hours = keyboard.nextInt();
while(true)
{
if(hours > 0)
break;
else
{
System.out.println("Invalid Input");
System.out.print("How many hours did you work on week " + (week) + ": ");
hours = keyboard.nextInt();
}
}
week++;
totalHours = totalHours + hours;
if(hours > 40)
{
System.out.println("Regular Hours: 40 Overtime hours: " + (hours-40));
regularHours = regularHours + 40;
overtimeHours = overtimeHours + hours-40;
}
else
{
System.out.println("Regular Hours: " + (hours) + " Overtime hours: 0.00");
regularHours = regularHours + hours;
}
System.out.println("Would you like to enter more hours?(y/n) ");
choice = keyboard.next();
if(choice.equals("n"))
break;
}
}
public static void display()
{
System.out.println(" -------------Display Summary----------------");
System.out.println("Regular Hours: " + (regularHours) + " Overtime hours: " + (overtimeHours));
}
public static void paystub(String firstName, String lastName)
{
double rate = 15.00;
header(firstName,lastName);
System.out.println("Weeks worked: " + week);
double overtimeIncome, grossIncome, regularIncome;
if (overtimeHours > 0)
{
regularIncome = 40*rate;
overtimeIncome = overtimeHours*1.5*rate;
}
else
{
overtimeIncome = 0.0;
regularIncome = regularHours*rate;
}
grossIncome = overtimeIncome + regularIncome;
System.out.println("Regular Pay: " + regularHours + " hours * $" + rate + " = $" + regularIncome );
System.out.println("Overtime Pay: " + overtimeHours + " hours * $" + rate + "* 1.5 = $" + overtimeIncome );
System.out.println("Gross Income: $" +grossIncome );
insuranceDeduction = insuranceDeduction*(week-1);
double taxes = (grossIncome- insuranceDeduction )*0.3;
double takeHome = grossIncome-taxes- insuranceDeduction;
System.out.println("Medical and Dental Insurance: $" + insuranceDeduction);
System.out.println("Federal Taxes: $" + taxes);
System.out.println("Takehome Income: $" + takeHome);
}
public static void main(String[] args)
{
Scanner keyboard = new Scanner (System.in);
System.out.print("What is your first name? ");
String firstName = keyboard.next();
System.out.print("What is your last name? ");
String lastName = keyboard.next();
while(true)
{
int choice = mainMenu();
if(choice == 1)
{
inputHours();
}
else if(choice == 2)
{
display();
}
else if(choice == 3)
{
paystub(firstName,lastName);
break;
}
else
System.out.println("Invalid Input");
}
System.out.println(" ************************************");
System.out.println("Thanks for using out system!");
System.out.println("************************************");
}
}
/*
output:
What is your first name? Hansel
What is your last name? Ong
--------------Main Menu----------------
1. Enter Hours Worked
2. Display Summary
3. Print Paystub (End program)
Please choose from the above options: 1
-------------Entering Hours----------------
How many hours did you work on week 1: 43
Regular Hours: 40
Overtime hours: 3
Would you like to enter more hours?(y/n)
n
--------------Main Menu----------------
1. Enter Hours Worked
2. Display Summary
3. Print Paystub (End program)
Please choose from the above options: 2
-------------Display Summary----------------
Regular Hours: 40
Overtime hours: 3
--------------Main Menu----------------
1. Enter Hours Worked
2. Display Summary
3. Print Paystub (End program)
Please choose from the above options: 3
************************************
Paystub for Ong, Hansel
************************************
Weeks worked: 2
Regular Pay: 40 hours * $15.0 = $600.0
Overtime Pay: 3 hours * $15.0* 1.5 = $67.5
Gross Income: $667.5
Medical and Dental Insurance: $25
Federal Taxes: $192.75
Takehome Income: $449.75
************************************
Thanks for using out system!
************************************
*/