Answer to Question #318561 in Java | JSP | JSF for oslo

Question #318561

Question 3: (Inheritance)

Create an abstract class called Employee that has an abstract method call computePay() which

computes the total pay per employee using the rate per hour = $50. The method should accept

the number of hours the employee has worked. Create a child class called employeeChild and

provide the implementation. In the main method invoke that method and get the number of hours

worked from the user and pass it to the called method.


1
Expert's answer
2022-03-26T06:42:45-0400
// ---------- Employee.java ---------- abstract class
public abstract class Employee {
    public abstract void calculatePay(double hour);
}

import java.util.Scanner;

class EmployeeChild extends Employee{

    public final double ratePerHour = 50;
    @Override
    public void calculatePay(double hour) {
        System.out.print("Total salary per employee = " + (ratePerHour*hour) + "$");
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        EmployeeChild employeeChild = new EmployeeChild();

        int hour = in.nextInt();
        employeeChild.calculatePay((double) hour);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS