28.2k views
0 votes
Write an application that calculates and displays the weekly salary for an employee. The main() method prompts the user for hourly pay rate, regular hours, and overtime hours. Create a separate method to calculate overtime pay, which is regular hours times the pay rate plus overtime hours time 1.5 times rate; return the result to the main() method to be displayed

User MeTitus
by
6.4k points

1 Answer

2 votes

Answer:

// here is program in java.

// import package

import java.util.*;

// class definition

class Main

{

// method to calculate weekly salary

public static double fun(int h_p_r,int r_h,int o_h)

{

// calculate weekly salary

double weekly_salary=(h_p_r*r_h)+(o_h*h_p_r*1.5);

// return salary

return weekly_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);

// ask to enter hourly pay rate

System.out.print("enter hourly pay rate: ");

// read hourly pay rate

int hourly_pay_rate=scr.nextInt();

// ask to enter regular hours

System.out.print("enter regular hours: ");

//read regular hours

int regular_hours=scr.nextInt();

// ask to enter overtime hours

System.out.print("enter overtime hours : ");

// read overtime hours

int overtime_hours=scr.nextInt();

// call the method

System.out.println("weekly salary of an employee :"+fun(hourly_pay_rate,regular_hours,overtime_hours));

}catch(Exception ex){

return;}

}

}

Step-by-step explanation:

Read hourly pay rate, regular hours and overtime hours from user.Call the method fun() with these parameters.There weekly salary is calculated by multiply regular hours with hourly_pay_rate and overtime hours with 1.5 time of hourly_pay_rate.Sum both of them, this will be the weekly salary.return this to main method and print it.

Output:

enter hourly pay rate: 20

enter regular hours: 40

enter overtime hours : 10

weekly salary of an employee :1100.0

User Gospes
by
5.7k points