Answer:
// import package
import java.util.*;
// class definition
class Salary
{
// method to calculate weekly salary
public static double fun(int p_rate,int r_hour,int o_hour)
{
// calculate weekly salary
double w_salary=(p_rate*r_hour)+(o_hour*p_rate*1.5);
// return salary
return w_salary;
}
// main method of the class
public static void main (String[] args) throws java.lang.Exception
{
try{
// object to read value from user
Scanner scr=new Scanner(System.in);
System.out.print("enter hourly pay rate: ");
// read hourly pay rate
int p_rate=scr.nextInt();
System.out.print("enter regular hours: ");
//read regular hours
int r_hour=scr.nextInt();
System.out.print("enter overtime hours : ");
// read overtime hours
int o_hour=scr.nextInt();
// call the method
System.out.println("weekly salary of an employee :"+fun(p_rate,r_hour,o_hour));
}catch(Exception ex){
return;}
}
}
Step-by-step explanation:
Read hourly pay rate, regular hours and overtime hours from user.Call the method sal() with these parameters.There weekly salary is calculated by multiply regular hours with p_rate and overtime hours with 1.5 time of p_rate.Sum both of them, this will be the weekly salary.return this to main method and print it.
Output:
enter hourly pay rate: 50
enter regular hours: 35
enter overtime hours : 15
weekly salary of an employee :2875.0