Question: JAVA HELP: class Workaholic { public static final int RETIREMENT_AGE = 65; public static final int OVERTIME = 500; private String name = null; private

JAVA HELP:

class Workaholic { public static final int RETIREMENT_AGE = 65; public static final int OVERTIME = 500; private String name = null; private int age = 0; private float earned = 0.0f; private float hourlyIncome = 0.0f;

public Workaholic(String name, float hourlyIncome, int age) { this.name = name; this.hourlyIncome = hourlyIncome; this.age = age; } public void work(int hours) { for(int i = 1; i<=hours; i++) earned += hourlyIncome; for(int j = 1; j<=OVERTIME; j++) earned += hourlyIncome; } public void work() { while(age++ < RETIREMENT_AGE) work(2000); } public String info() { return name + " earned " + earned; } }

class Worker { public static final int RETIREMENT_AGE = 65

public Worker(String name, float hourlyIncome, int age, Worker coWorker) { this.name = name; this.hourlyIncome = hourlyIncome; this.age = age; this.coWorker = coWorker; } public void work(int hours) { for(int i = 1; i<=hours; i++) { earned += hourlyIncome; if(coWorker!=null && i%5==0) delegate(1); } } public void work() { while(age++ < RETIREMENT_AGE) work(1600); } private void delegate(int hours) { coWorker.work(hours); } public String info() { return name + " earned " + earned; }

public static void main(String[] args) { Worker jane = new Worker("Jane", 20, 25, null); Worker john = new Worker("John", 20, 45, jane); Workaholic bill = new Workaholic("Bill", 20, 25);

john.work(); jane.work(); bill.work();

System.out.println(john.info()); System.out.println(jane.info()); System.out.println(bill.info()); }

} Simplify the given code as much as possible using class inheritance (but do not remove classes or functionality of the given classes). Also, simplify the loops in the given code, where possible. Make sure that your new versions of the classes yield the same results as the old versions when used in main().

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!