Ask Question

Write a java program to calculate employee pay using methods. There must be an overtime pay method and a straight pay method and a print method. Using either scanner or JoptionPane, input the employee number, the hours worked, and the hourly pay for an employee. If the employee worked over 40 hours, call the overtime method, if not call the straight time method. Calculate the pay amount in one of the 2 methods. Call a third method to print the employee number and the pay amount.

+5
Answers (1)
  1. 29 July, 23:22
    0
    Here is the code to solve this question written in Java programming language.

    import java. util. Scanner;

    class Main {

    public static void main (String[] args) {

    Scanner in = new Scanner (System. in);

    int hours;

    float hourly_fee, payment;

    System. out. println ("Enter the amount of hours worked");

    hours = in. nextInt ();

    System. out. println ("Enter the fee per hour");

    hourly_fee = in. nextFloat ();

    if (hours > = 0 && hours < = 40) {

    payment = straighttime (hours, hourly_fee);

    }else{

    payment = overtime (hours, hourly_fee);

    }

    printPayment (payment);

    }

    public static float overtime (int hours, float fee) {

    return (hours*fee*Float. parseFloat ("1.25"));

    }

    public static float straighttime (int hours, float fee) {

    return (hours * fee);

    }

    public static void printPayment (float payment) {

    System. out. println ("Your total payment is: "+payment);

    }

    }

    Explanation:

    The commented code to solve this question is given below:

    //Import the Scanner package to manage input from console.

    import java. util. Scanner;

    //Create the Main class

    class Main {

    //Create the static void method to execute the logic of the program

    public static void main (String[] args) {

    /*

    Create an "in" object that manage the console inputs, declare the

    variables to manage the hours and the payment. "int" and "float"

    */

    Scanner in = new Scanner (System. in);

    int hours;

    float hourly_fee, payment;

    System. out. println ("Enter the amount of hours worked");

    hours = in. nextInt ();

    System. out. println ("Enter the fee per hour");

    hourly_fee = in. nextFloat ();

    / / Evaluate the conditions to call overtime or straighttime given that the hours are greater than 40.

    if (hours > = 0 && hours < = 40) {

    payment = straighttime (hours, hourly_fee);

    }else{

    payment = overtime (hours, hourly_fee);

    }

    printPayment (payment);

    }

    public static float overtime (int hours, float fee) {

    /*

    This method is of type float and returns the total payment multplied by 1.25 that is the extra fee for overtime.

    */

    return (hours*fee*Float. parseFloat ("1.25"));

    }

    public static float straighttime (int hours, float fee) {

    /*

    This method is of type float and returns the total payment of straight hours.

    */

    return (hours * fee);

    }

    public static void printPayment (float payment) {

    /*

    This methods print out in the console the total payment.

    */

    System. out. println ("Your total payment is: "+payment);

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a java program to calculate employee pay using methods. There must be an overtime pay method and a straight pay method and a print ...” 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