Respuesta :
Answer:
Following is the definition of method pay in Java:
public static double pay(double sal, int hr)
{
double pay;
if(hr>8)
{
pay = sal*8 + (1.5*sal*(hr-8));
}else
pay = sal*hr;
return pay;
}
Explanation:
Sample program to demonstrate above method:
public class Main
{
public static void main(String[] args) {
System.out.println(pay(5.50, 6));
System.out.println(pay(4.00, 11));
}
public static double pay(double sal, int hr)
{
double pay;
if(hr>8)
{
pay = sal*8 + (1.5*sal*(hr-8));
}else
pay = sal*hr;
return pay;
}
}
Output:
33.0
50.0
Following are the Java program to the given question:
Program:
public class Main//defining a class-main
{
public static double pay(double salary, int hours)//defining a method pay that takes 2 parameters
{
if(hours <= 8) //defining if block that checks hours value less than equal to 8
{
return salary * hours;//using return that calculates salary
}
else //else block
{
return (salary * 8) + (salary * 1.5) * (hours - 8);//using return that calculate salary
}
}
public static void main(String[] args) //main method
{
System.out.println(pay(5.50,6));//calling method and print return value
System.out.println(pay(4.00,11));//calling method and print return value
}
}
Program Explanation:
- Defining a class Main, inside the defining the method "pay" that takes two variable "salary, hours" inside the parameter.
- Inside the method, a statement is used that checks the hour's value and uses a return variable that calculates the salary value as per the question.
- Outside the method, the main method is declared, inside these two print methods is used that call the "pay" method that accepts the value in the parameters and returns its value.
Output:
Please find the attached file.
Find out more information about the Program here:
brainly.com/question/24379089
