Question: The Payable Interface An interface declares one or more methods but does not implement the methods. For example, the Payable interface should declare the get





The Payable Interface An interface declares one or more methods but does not implement the methods. For example, the Payable interface should declare the get Payment Amount method. The Invoice and Employee Classes Both the Employee class and Invoice class implements Payable interface, which is a promise to implement the getPaymentAmount method. This allows Employee objects and Invoice objects to be processed polymorphically as Payable objects because they all implement the getPaymentAmount method. The Invoice class is a basic class with instance variables o part the part number o description the part description count how many o price - cost per item A toString method returns String representation of Invoice Object. A getPaymentAmount method returns the cost of the invoice . Note: toString and getPaymentAmount use the get methods rather than directly accessing the variables. The Employee class Should be an abstract class. instance variables. O first - first name of employee o last - last name of employee ssn - SSN of employee A toString method returns String representation of Employee Object. O Subclasses of Employee Each of the subclasses have the following features: The parameters of its constructor include values to initialize all the instance variables of the class and its superclasses. The first line of code in the constructor calls the constructor of the immediate superclass. Note the use of the super keyword. This is good practice in inheritance hierarchies. The getPaymentAmount method is implemented, fulfilling the promise made by the Employee class. The toString method combines the result of the toString method of the superclass with additional information. Again, note the use of the super keyword. The constructor, getPaymentAmount and toString methods use the getters and setters to get and set the instance variables. One reason is that instance variables from the superclasses are private, so there is no other way to access and modify these variables. The other reason is that the setters include code to validate (or at least partially validate) the new values. Commission Employee Class Commission employees are paid a percentage of their sales instance variabes o gross Sales - gross sales of employee (should satisfy the condition
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
