Can you help me with this? Write a Java program that includes a method called pa
ID: 644765 • Letter: C
Question
Can you help me with this? Write a Java program that includes a method called pay that accepts two parameters: A real number for an employee's hourly wage and an integer for the number of hours the employee worked that day. The method should return how much money to pay the employee for this day. For example, the call pay (5.50, 6) should return 33.0.
The employee should receive "overtime" pay of 1.5 times the normal hourly wage for any hours above 8. For example, the call pay (4.00, 11) should return 50.0 (calculated as (4.00 * 8) + (6.00 *3). Include in the main method of this program four calls to the pay method. Two calls, each one using the example data given above and two calls, each one using data that you determine.
Explanation / Answer
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class payEmployee
{
public static void main(String args[]) throws IOException
{
InputStreamReader istream = new InputStreamReader(System.in) ;
BufferedReader bufRead = new BufferedReader(istream) ;
System.out.println("Enter the total working hours:");
int hours=Integer.parseInt(bufRead.readLine()); //readings hours as string value
System.out.println("Enter the wage per hour:");
double wage=Double.parseDouble(bufRead.readLine());//readings wages as string value
double total_wage=pay(wage,hours);
System.out.println("The total wage for the employee is:"+total_wage);
}
private static double pay(double wage, int hours)
{
int overtime;
double overtime_wage;
double regular_wage;
double total_wage;
if(hours>8)
{
regular_wage=8*wage;
overtime=hours-8;// calculating additional wage in the rate of 1.5
overtime_wage=(1.5*wage)*overtime;
total_wage=overtime_wage+regular_wage;
return total_wage;
}
else
{
regular_wage=hours*wage;// calculating normal wage if working hours is less than or equal to 8
return regular_wage;
}
}
}