Answer:
The java program is as follows.
import java.util.Scanner;
public class Calculator{
// variable to hold user input for total hours worked
static int hours;
// variable showing minimum working hours
static int min_hours = 40;
// variable to hold user input for hourly wage
static double wage;
// variable to hold the overtime factor for extra hours worked
static double overtime_factor = 1.5;
// variable to hold the calculated total wages
static double total_wage;
public static void main(String args[]) {
// object of Scanner variable initialized to enable user input
Scanner sc = new Scanner(System.in);
// user input taken for total working hours
System.out.println("Enter the hours worked ");
hours = sc.nextInt();
// user input taken for wages earned per hour
System.out.println("Enter the hourly wage ");
wage = sc.nextDouble();
// total wages calculated depending upon the number of hours worked
// overtime factor taken into account when overtime hours worked
if(hours <= min_hours)
total_wage = wage*hours;
if(hours > min_hours)
{
total_wage = wage*min_hours;
total_wage = total_wage + ( (wage*overtime_factor)*(hours - min_hours) );
}
// total wage earned is displayed
System.out.println("The total wages earned is " + total_wage);
}
}
OUTPUT
Enter the hours worked
44
Enter the hourly wage
10
The total wages earned is 460.0
Step-by-step explanation:
The java program given above works as follows.
1 - User input is taken for hours and wages.
2 - The overtime factor is taken as 1.5 as per the question.
3 – Two if statements are used to compute total wages which depend on the number of hours worked.
4 - For overtime hours, the wage is obtained as a product of normal wage and overtime factor. These values are used to compute total wage for overtime.
5 – First, total wage for normal hours is computed using user entered values.
6 – Next, if overtime hours are present, total wages for overtime is added to the total wages computed in step 5.