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.
- Run the program, observe the output. Change 40 to 35 (France's work week), and run again.
- Generalize the program further by using a variable workWeeksPerYear. Run the program. Change 50 to 52, and run again.
- 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
Get step-by-step solutions from verified subject matter experts
