Ask Question

Write a method named pay that accepts two parameters: a real number for a TA's salary, and an integer for the number of hours the TA worked this week. The method should return how much money to pay the TA. For example, the call pay (5.50, 6) should return 33.0.

The TA should receive "overtime" pay of 1 ½ normal salary for any hours above 8. For example, the call pay (4.00, 11) should return (4.00 * 8) + (6.00 * 3) or 50.0.

+3
Answers (1)
  1. 24 August, 08:05
    0
    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
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a method named pay that accepts two parameters: a real number for a TA's salary, and an integer for the number of hours the TA worked ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers