Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

NOTE: Use true encapsulation (design all data fields as private and reach them just using get/set methods) and inheritance practice in your implementation. Your project

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

NOTE: Use true encapsulation (design all data fields as private and reach them just using get/set methods) and inheritance practice in your implementation. Your project have to consist of 8 classes: Payable, Invoice, Employee, SalariedEmployee, HourlyEmployee, Commision Employee, BasePlusCommision Employee, PayableInterface Test NOTE: Do not use earnings() method for this homework instead, getPaymentAmount() of Payable interface will be implemented. NOTE: Do not take input from user!! HOMEWORK CEO of Factory X make a request to your software company about design a program that calculates Factory Xs payment amount which will be made for employees and invoices. Create Invoice, Payable (interface), Employee, SalariedEmployee, HourlyEmployee, Commission Employee, BasePlusCommission Employee, and Test (main) class according to requirements given below. Hierarchy between classes: interface Payable Invoice Employee Salaried Employee Commission Employee HourlyEmployee BasePlusCommissionEmployee Invoice implements Payable public class Invoice implements Payable Employee implements Payable Employee is abstract superclass. Each employee has a first name, a last name and a social security number. There is no get PaymentAmount () method in Employee class public abstract class Employee implements Payable Salaried Employee, Hourly Employee, Commission Employee is an Employee. BasePlusCommission Employee is a Commission Employee. Each class has different behavior in getPaymentAmount() and toString() methods. NOTE: There is no getPaymentAmount() method in Employee class. Factory X's payment amount which will be made for its employees on a weekly basis. The employees are of four types: Salaried employees are paid a fixed weekly salary regardless of the number of hours worked Hourly employees are paid by the hour and receive overtime pay (i.e., 1.5 times their hourly salary rate) for all hours worked in excess of 40 hours Commission employees are paid a percentage of their sales Base plus commission employees receive a base salary plus a percentage of their sales. Factory X's payment amount which will be made for invoice: Invoice 's payment amount is calculated by multiplying quantity and price per item. getPaymentAmount() toString() Employee Salaried- Employee firstName lastName Not implemented social security number: SSN salaried employee: firstName lastName weeklySalary social security number: SSN weekly salary: weeklySalary if Chours 40) hourly employee: firstName lastName { social security number: SSN 40 * wage + hourly wage: wage; hours worked: hours (hours - 40 ) * wage * 1.5 } Hourly- Employee Commission- Employee commissionate grossSales commission employee: firstName lastName social security number: SSN gross sales: grossSales; commission rate: commissionRate base salaried commission employee: firstName lastName social security number: SSN gross sales: grossSales; commission rate: commission Rate; base salary: baseSalary BasePlus- Commission- Employee (commissionRate + grossSales) + baseSalary CLASSES Payable Design an interface named Payable with a method: double getPaymentAmount(). public interface Payable { double get Payment Amount(); } Invoice public class Invoice implements Payable Create a class named Invoice contains billing information for only one kind of part: implements Payable private partNumber, partDescription, quantity and pricePerItem data fields 4 argument Constructor: Validation: quantitiy must be >=0, price must be > Make necessary assignments. get/set methods for partNumber, partDescription, quantity and pricePerItem Apply validation in set methods. toString() method returns string representation of an object. Implement Payable's getPaymentAmount() that returns multiplication of quantity and pricePerItem. O O Employee Employee is abstract superclass. implements Payable private firstName, lastName and social security number (SSN) data fields. 3 argument Constructor get/set methods for firstName, lastName and social security number (SSN) toString() method returns string representation of an object. getPaymentAmount() method of Payable interface should not be coded in Employee class. The method content changes employee to employee so, it should be coded in all subclasses of Employee and Invoice Employee class must be declared Abstract to avoid compilation error because getPaymentAmount() is not implemented in the class. Salaried Employee Subclass of Employee private weekly Salary data field 4 argument Constructor: Use super keyword when invoking superclass constructor, Validation: weeklySalary must be >= 0 Make necessary assignments. get/set methods for weekly Salary Apply validation in set method. Implement get PaymentAmount() and override toString() methods according to table above. Use super if necessary Hourly Employee Subclass of Employee private wage, hours data fields 5 argument Constructor: Use super keyword when invoking superclass constructor, Validation: wage must be >=0, hours must be >=0 and =0, commissionRate>0 and =0 Make necessary assignments. get/set methods for baseSalary Apply validation in set methods. Implement get PaymentAmount() and override toString() methods according to table above. Use super if necessary Test (Main class) You may use your own preferred data field values while creating objects. Create Payable type array which contains 6 elements. Payable payableObjects[] = new Payable[ 6 ]; Initialize array with references of 2 Invoice object, a reference of SalariedEmployee, HourlyEmployee, Commission Employee, BasePlusCommission Employee repectively. payableObjects [ 0 ] = new Invoice (....); payableObjects[ 1 ] = new Invoice (....); payableObjects [ 2 ] = new SalariedEmployee (....); payableObjects[3] = new HourlyEmployee (....); payableObjects [ 4 ] new Commission Employee (....); payableObjects [ 5 ] new BasePlusCommission Employee (....); Polymorphic Usage of Interface: For each element in the array; Print the element Decide if element is a BasePlusCommission Employee or not if ( payableObjects[i] instanceof BasePlusCommissionEmployee ) If so, increase baseSalary of employee by adding %10 of current baseSalary and print new baseSalary Print getPaymentAmount() Print the class name of each object in the array using default superclass Object's related method. payableObjects[j].getClass().getName() Sample run : ---- Invoices and Employees processed polymorphically:-- invoice: part number: 01234 (seat) quantity: 2 price per item: $375,00 payment amount: $750,00 invoice: part number: 56789 (tire) quantity: 4 price per item: $79,95 payment amount: $319,80 salaried employee: John Smith social security number: 111-11-1111 weekly salary: $800,00 payment amount: $800,00 hourly employee: Karen Price social security number: 222-22-2222 hourly wage: $16,75; hours worked: 40,00 payment amount: $670,00 commission employee: Sue Jones social security number: 333-33-3333 gross sales: $10.000,00; commission rate: 0,06 payment amount: $600,00 base-salaried commission employee: Bob Lewis social security number: 444-44-4444 gross sales: $5.000,00; commission rate: 0,04; base salary: $300,00 new base salary with 10% increase is: $330,00 payment amount: $530,00 Payable object is a Invoice Payable object 1 is a Invoice Payable object 2 is a SalariedEmployee Payable object 3 is a HourlyEmployee Payable object 4 is a Commission Employee Payable object 5 is a BasePlusCommissionEmployee a

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sql All In One For Dummies 7 Books In One

Authors: Allen G Taylor ,Richard Blum

4th Edition

1394242298, 978-1394242290

More Books

Students also viewed these Databases questions

Question

LOQ 13-4: How can we share our views more effectively?

Answered: 1 week ago

Question

9. Understand the phenomenon of code switching and interlanguage.

Answered: 1 week ago