Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following program calculates yearly and monthly salary given an hourly wage. The program assumes work-hours-per-week limit of 40 and work-weeks-per-year of 50. Overtime refers

The following program calculates yearly and monthly salary given an hourly wage. The program assumes work-hours-per-week limit of 40 and work-weeks-per-year of 50.

Overtime refers to hours worked per week in excess of some weekly limit, such as 40 hours. Some companies pay time-and-a-half for overtime hours, meaning overtime hours are paid at 1.5 times the hourly wage.

Overtime pay can be calculated with pseudocode as follows (assuming a weekly limit of 40 hours):

weeklyLimit = 40 if weeklyHours <= weeklyLimit weeklySalary = hourlyWage * weeklyHours else overtimeHours = weeklyHours - weeklyLimit weeklySalary = hourlyWage * weeklyLimit + (overtimeHours * hourlyWage * 1.5) 

1.Run the program and observe the salary earned.

2.Modify the program to read user input for weeklyHours. Run the program again.

import java.util.Scanner;

public class Salary { public static void main(String [] args) { Scanner scnr = new Scanner(System.in); int hourlyWage = 0; int weeklyHours = 0; int weeklySalary = 0; int overtimeHours = 0; final int WEEKLY_LIMIT = 40; System.out.println("Enter hourly wage: "); hourlyWage = scnr.nextInt();

// FIXME: Get user input value for weeklyHours weeklyHours = 40;

if (weeklyHours <= WEEKLY_LIMIT) { weeklySalary = weeklyHours * hourlyWage; } else { overtimeHours = weeklyHours - WEEKLY_LIMIT; weeklySalary = (int)((hourlyWage * WEEKLY_LIMIT) + (hourlyWage * overtimeHours * 1.5)); } System.out.print("Weekly salary is: " + weeklySalary); return; } }

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

Oracle Database 10g Insider Solutions

Authors: Arun R. Kumar, John Kanagaraj, Richard Stroupe

1st Edition

0672327910, 978-0672327919

More Books

Students also viewed these Databases questions