Question: For this Minilab, you will write an abstract class and 3 subclasses of your abstract class. The classes you will write will be used in



For this Minilab, you will write an abstract class and 3 subclasses of your abstract class. The classes you will write will be used in a future program. The classes are to simulate different categories of workers in a semiconductor fabrication plant ("fab"). The 3 subclasses will have some common data and will have to have a compareTo method, so those data/methods can be implemented at and inherited from the parent class. However, each subclass has to know how to calculate its own bonus - since that calculation is specific to a class, each class must implement their own calculateBonus method. So calculateBonus will be an abstract method in the parent class. The classes vou will write are related as shown (more detail is below): letails on each class are below: he Worker class is abstract (so an instance cannot be created; it only exists to give data/methods to its ubclasses and to tell subclasses to implement abstract methods). Worker should implement the Comparable iterface, so it will be declared like this: public abstract class Worker implements Comparable> - data: a String to hold the name an int to hold the rating ( 1 through 5 ) an int to hold the id The data should not be public, but should still be inheritable. - Parameterized constructor: you do not have to write a constructor, since an instance of Worker cannot be created. However, writing one will allow all the subclasses to use it by calling super(with arguments). That way, all of the error checking can be done in the same place and it can set the data described in the Worker class. A parameterized constructor would receive a name (as a String), a rating (as an int), and an id (as an int). It should first check to see if the rating received is between 1 and 5 (inclusive). If not, throw new IllegalArgumentException("'your deseriptive String here"); But if the rating is OK, then set the values in the instance being ereated. - A compareTo(Worker another) is required by the interface. The interface is built into Java so you can look it up. Our implementation is that it should return a positive number if it's own rating is > another's rating and a negative number if it's own rating is = another's rating, then look at the id. In that case, return a positive number if it's own id > another's id and a negative number if it's own id OK, then set the values in the instance being created. Note that the parameterized constructor could call the parent's constructor using super(arguments it expects). That will do the error checking and set the first 3 values, leaving Processor's constructor to just set the last one. - calculateBonus(double multiplier) will return the bonus earned by each instance. A Processor's bonus will be its bonus Target * multiplier. - compareTo(Worker another) is inherited. - toString( returns the String shown in the example in Worker's toString, but also with ", target:" and the bonusTarget at the end. So Processor's toStringO could return super.toString0 with its bonus concatenated at the end. As an example, an instance of Processor whose name is "Karen Jones" and whose rating is 3 and whose id is 123 and whose bonusTarget is 3017.50 would be returned by toString() as: The Specialist class is a subclass of Worker. It has: - data: (the name, rating, and id that were inherited) a double for the bonusTarget (which is the bonus before the multiplier is applied). a double for the profitSharing (which is the profit sharing target before the multiplier) - parameterized constructor: receives a name (as a String), a rating (as an int), an id (as an int), and a bonusTarget (as a double) and a profitSharing (as a double). It should first check to see if the rating received is between I and 5 (inclusive). If not, throw new IllegalArgumentException("your descriptive String here"); But if the rating is OK, then set the values in the instance being created. Note that the parameterized constructor could call the parent's constructor using super(arguments it expects). That will do the error checking and set the first 3 values, leaving Processor's constructor to just set the last two. - calculateBonus(double multiplier) will return the bonus earned by each instance. A Processor's bonus will be its (bonusTarget+profitSharing) * multiplier. - compareTo(Worker another) is inherited. - toString() returns the String shown in the example in Worker's toString, but also with ", target:" and the bonusTarget, then ", profit:" and the profitSharing concatenated at the end. So Specialist's toString O could return super.toString O with the additional words and data concatenated at the end. As an example, an instance of Specialist whose name is "Karen Jones" and whose rating is 3 and whose id is 123 and whose bonusTarget is 3017.50 and whose profitSharing is 2050.80 would be returned by toString ( as
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
