Question: The program below has been generalized to read a user's input value for hourlyWage. Run the program. Notice the user's input value of 10 is
The program below has been generalized to read a user's input value for hourlyWage.
Run the program. Notice the user's input value of 10 is used. Modify that input value, and run again.
Generalize the program to get user input values for workHoursPerWeek and workWeeksPerYear (change those variables' initializations to 0). Run the program.
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.
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 = 0; int workHoursPerWeek = 40; int workWeeksPerYear = 50; int monthsPerYear = 12; // FIXME: Declare as final and use standard naming int annualSalary = 0; int monthlySalary = 0; System.out.println("Enter hourly wage: "); hourlyWage = scnr.nextInt();
// FIXME: Get user input values for workHoursPerWeek and workWeeksPerYear
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);
return; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
