Introduction to computer class, Java programming through eclipse: Ue the followi
ID: 3588107 • Letter: I
Question
Introduction to computer class, Java programming through eclipse:
Ue the following criteria to create the code: SALARY
Input first and last name
- Output the names last, first in your output
- Make the federal withholding rate a constant 20% (not an input value)
No state tax
Generate two new values: regular pay and overtime pay
- 40 hours workedor less
- Regular pay is pay rate * hours worked
- Overtime pay is 0
Otherwise
- Regular pay is pay rate * 40
- Overtime is pay rate * (hours –40)* 1.5
- Gross pay is then regular pay + overtime pay
Output should be similar to the instructions in the bookexcept:
- Regular and overtime pay includedostate tax not included
- all currency should be rounded to 2 decimals
SAMPLE CODE:
Sample run: Enter first and last name: Fred Flintstone Enter hours worked: 40.25 Enter hourly pay rate: $36.00 Employee name: Flintstone, Fred Hours worked: 40.25 Hourly Rate: $36.00 Gross Pay: $1453.50 Regular Pay: $1440.00 Overtime Pay: $13.50 Deductions: Federal Tax: $290.70 Total deductions: $290.70 Net Pay: $1162.80Explanation / Answer
import java.util.Scanner;
public class Salary{
public static void main(String []args){
Scanner sc = new Scanner(System.in).useDelimiter("\s");
System.out.print("Enter first and last name: ");
String firstName = sc.next();
String lastName = sc.next();
//Scanner sc1 = new Scanner(System.in);
sc.nextLine();
System.out.print(" Enter hours worked: ");
double hoursWorked = sc.nextDouble();
System.out.print(" Enter hourly pay rate: $");
sc.nextLine();
double hourlyPayRate = sc.nextDouble();
System.out.print(" Employee Name: "+lastName+", "+firstName);
System.out.print(" Hours Worked: "+hoursWorked);
System.out.print(" Hourly Rate: $"+hourlyPayRate);
double grossPay,regularPay,overTimePay;
if(hoursWorked<=40)
{
grossPay = hoursWorked*hourlyPayRate;
regularPay = grossPay;
overTimePay = 0.00;
}
else
{
regularPay = 40*hourlyPayRate;
overTimePay = (hoursWorked - 40)*hourlyPayRate*1.5;
grossPay = regularPay+overTimePay;
}
System.out.print(" Gross Pay: $"+grossPay);
System.out.print(" Regulat Pay: $"+regularPay);
System.out.print(" Overtime Pay: $"+overTimePay);
double deductions = grossPay*0.2;
System.out.print(" Deductions:");
System.out.print(" Federal Tax: $"+deductions);
System.out.print(" Total Deductions: $"+deductions);
System.out.print(" Net Pay: $"+(grossPay-deductions));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.