Answer to Question #231870 in Java | JSP | JSF for jerry

Question #231870

Develop a java application using Inheritance as per the following. Create a class

Worker and derive two classes DailyWorker and SalariedWorker from it. Every

worker has name, salary rate. Provide a method ComPay(int hours) to compute the

week pay of every worker. A DailyWorker is paid on the basis of number of days

he/she works. The SalariedWorker gets paid the wage for 40 hours a week no

matter what actual hours is. Implement this scenario to calculate the pay of workers.

You are expected to use the concept of Inheritance with proper run time

polymorphism


1
Expert's answer
2021-09-01T23:57:36-0400


public class Main
{
	public static void main(String[] args) {
		DailyWorker d=new DailyWorker();
		d.ComPay(6);
		SalariedWorker s=new SalariedWorker();
		s.ComPay(40);
	}
}
class Worker{
    protected String name; 
    protected double salary_rate=1250;
    
    public void ComPay(int hours){
        System.out.println("Pay= "+(hours*salary_rate));
    }
}


class DailyWorker extends Worker{
    private int day;
    public void ComPay(int days){
        System.out.println("Pay= "+(days*salary_rate));
    }
}


class SalariedWorker extends Worker{
    public void ComPay(int hours){
        System.out.println("Pay= "+(40*salary_rate));
    }
}

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