Question: Calculate salary: Generalize a program with variables and input. The following program uses a variable workHoursPerWeek rather than directly using 40 in the salary calculation

Calculate salary: Generalize a program with variables and input.

The following program uses a variable workHoursPerWeek rather than directly using 40 in the salary calculation expression.

  1. Run the program, observe the output. Change 40 to 35 (France's work week), and run again.
  2. Generalize the program further by using a variable workWeeksPerYear. Run the program. Change 50 to 52, and run again.
  3. Introduce a variable monthlySalary, used similarly to annualSalary, to further improve program readability.

public class Salary { public static void main(String[] args) { int hourlyWage; int workHoursPerWeek; int annualSalary;

// FIXME: Declare and initialize variable workWeeksPerYear, then replace the 50's below

hourlyWage = 20; workHoursPerWeek = 40; annualSalary = hourlyWage * workHoursPerWeek * 50; System.out.print("Annual salary is: "); System.out.println(annualSalary); System.out.print("Monthly salary is: "); System.out.println((hourlyWage * workHoursPerWeek * 50) / 12); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!