Question: Calculate salary: Generalize a program with variables and input. The program below has been generalized to read a user's input value for hourlyWage. Run the

Calculate salary: Generalize a program with variables and input.

The program below has been generalized to read a user's input value for hourlyWage.

  1. Run the program. Notice the user's input value of 10 is used. Modify that input value, and run again.
  2. Generalize the program to get user input values for workHoursPerWeek and workWeeksPerYear (change those variables' initializations to 0). Run the program.
  3. monthsPerYear will never change, so declare that variable as final. Use the standard for naming final variables. Ex: final int MAX_LENGTH = 99. Run the program.
  4. Change the values in the input area below the program, and 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; int workHoursPerWeek; int workWeeksPerYear; int monthsPerYear; // FIXME: Declare as final and use standard naming int annualSalary; int monthlySalary;

monthsPerYear = 12; System.out.println("Enter hourly wage: "); hourlyWage = scnr.nextInt();

// FIXME: Get user input values for workHoursPerWeek and workWeeksPerYear workHoursPerWeek = 40; workWeeksPerYear = 50;

annualSalary = hourlyWage * workHoursPerWeek * workWeeksPerYear; System.out.print("Annual salary is: "); System.out.println(annualSalary); // FIXME: Change monthsPerYear to the final variable that uses the standard naming monthlySalary = (hourlyWage * workHoursPerWeek * workWeeksPerYear) / monthsPerYear; System.out.print("Monthly salary is: "); System.out.println(monthlySalary); } }

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!