PayCalculator. Java code needed. There are no specifics, this is for personal us
ID: 3560095 • Letter: P
Question
PayCalculator. Java code needed. There are no specifics, this is for personal use.
Create an abstract class PayCalculator that has an attribute payRate given in dollars per hour. The class should also have a method computePay(hours) that returns the pay for a given amount of time.
Derive a class RegularPay from PayCalculator, as described above. It should have a constructor that has a parameter for the pay rate. It should not override any of the methods. Then derive a class HazardPay from PayCalculator that overrides the computePay method. The new method should return the amount returned by the base class method multiplied by 1.5.
Explanation / Answer
public abstract class PayCalculator
{
public int payRate;
public int computePay(int hours)
{
return hours*payRate;
}
}
public class RegularPay extends PayCalculator
{
public RegularPay(int val)
{
payRate = val;
}
}
public class HazardPay
{
public int computePay(int hours)
{
return hours*payRate*1.5;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.