Placeholder

Exercise 10.16 Accounts Payable System Modification

$8.99

Description

In this exercise, we modify the accounts payable application of Figs. 10.11–10.15 to include the complete functionality of the payroll application of Figs. 10.4–10.9. The application should still process two Invoice objects, but now should process one object of each of the four Employee subclasses. If the object currently being processed is a BasePlusCommissionEmployee, the application should increase the BasePlusCommissionEmployee’s basesalary by 10%. Finally, the application should output the payment amount for each object. Complete the following steps to create the new application:
a) Modify classes HourlyEmployee (Fig. 10.6) and CommissionEmployee (Fig. 10.7) to place them in the Payable hierarchy as subclasses of the version of Employee (Fig. 10.13) that implements Payable. [Hint: Change the name of method earnings to getPaymentAmount in each subclass so that the class satisfies its inherited contract with interface Payable.]
b) Modify class BasePlusCommissionEmployee (Fig. 10.8) such that it extends the version of class CommissionEmployee created in part (a).
c) Modify PayableInterfaceTest (Fig. 10.15) to polymorphically process two Invoices,one SalariedEmployee, one HourlyEmployee, one CommissionEmployee and one BasePlusCommissionEmployee. First output a String representation of each Payable object.Next, if an object is a BasePlusCommissionEmployee, increase its base salary by 10%. Finally, output the payment amount for each Payable object.
SCREENSHOTS
SOLUTION
PAYMENT
The solution consists of:
A report word document for this assignment
All Java programs and classes
A Netbeans project in case you want to run the project on your computer.
Screenshots showing program running
Attachments [Move over files to preview content of those files]
Account_Payable_System.zip (425.96 KB)
Account-Payable-System-Screenshot-1.jpg
Account-Payable-System-Screenshot-2.jpg
Account-Payable-System-Screenshot-3.jpg
Account-Payable-System-Screenshot-4.jpg
Java Source Codes
BasePlusCommissionEmployee.java
CommissionEmployee.java
Employee.java
HourlyEmployee.java
Invoice.java
Payable.java
PayableInterfaceTest.java
PayrollSystemTest.java
SalariedEmployee.java
Netbeans Project
CommissionEmployee
pom.xml
src
main
java
BasePlusCommissionEmployee.java
CommissionEmployee.java
Employee.java
HourlyEmployee.java
Invoice.java
Payable.java
PayableInterfaceTest.java
PayrollSystemTest.java
SalariedEmployee.java
test
java
target
classes
.netbeans_automatic_build
BasePlusCommissionEmployee.class
CommissionEmployee.class
Employee.class
HourlyEmployee.class
Invoice.class
Payable.class
PayableInterfaceTest.class
PayrollSystemTest.class
SalariedEmployee.class
generated-sources
annotations
maven-status
maven-compiler-plugin
compile
default-compile
createdFiles.lst
inputFiles.lst
test-classes
.netbeans_automatic_build
Preview BasePlusCommissionEmployee.java
xx (xxxxxxxxxx < 0.0) { // xxxxxxxx xxxxxxxxxx xxxxx xxx xxxxxxxxxxxxxxxxxxxxxxxx("xxxx xxxxxx xxxx xx >= 0.0″);
}
this.baseSalary = baseSalary; }
// set base salary public void setBaseSalary(double baseSalary) { if (baseSalary < 0.0) { // validate baseSalary throw new IllegalArgumentException("Base salary must be >= 0.0″); }
this.baseSalary = baseSalary; }
// xxxxxx xxxx xxxxxx
xxxxxx xxxxxx xxxxxxxxxxxxx() { xxxxxx xxxxxxxxxx;}
// xxxxxxxxx xxxxxxxx; xxxxxxxx xxxxxx xxxxxxxx xx xxxxxxxxxxxxxxxxxx
@xxxxxxxx
xxxxxx xxxxxx xxxxxxxx() {
Preview CommissionEmployee.java
xx (xxxxxxxxxxxxxx <= 0.0 || xxxxxxxxxxxxxx >= 1.0) // xxxxxxxx
{
xxxxx xxx xxxxxxxxxxxxxxxxxxxxxxxx(“xxxxxxxxxx xxxx xxxx xx > 0.0 xxx < 1.0"); } if (grossSales < 0.0) { // validate throw new IllegalArgumentException("Gross sales must be >= 0.0″); }
this.grossSales = grossSales; this.commissionRate = commissionRate; }
// set gross sales amount public void setGrossSales(double grossSales) { if (grossSales < 0.0) { // validate xxxxx xxx xxxxxxxxxxxxxxxxxxxxxxxx("xxxxx xxxxx xxxx xx >= 0.0″);
}
xxxx.xxxxxxxxxx = xxxxxxxxxx;
}
Preview Employee.java
// xxx. 10.13: xxxxxxxx.xxxx
// xxxxxxxx xxxxxxxx xxxxxxxxxx xxxx xxxxxxxxxx xxxxxxx.
xxxxxx xxxxxxxx xxxxx xxxxxxxx xxxxxxxxxx xxxxxxx {
xxxxxxx xxxxx xxxxxx xxxxxxxxx;
private final String lastName; private final String socialSecurityNumber;
// constructor public Employee(String firstName, String lastName, String socialSecurityNumber) { this.firstName = firstName; this.lastName = lastName;
xxxx.xxxxxxxxxxxxxxxxxxxx = xxxxxxxxxxxxxxxxxxxx;
}
// xxxxxx xxxxx xxxx
xxxxxx xxxxxx xxxxxxxxxxxx() {xxxxxx xxxxxxxxx;}
Preview HourlyEmployee.java
xx (xxxx < 0.0) // xxxxxxxx xxxx { xxxxx xxx xxxxxxxxxxxxxxxxxxxxxxxx("xxxxxx xxxx xxxx xx >= 0.0″);
}
if ((hours < 0.0) || (hours > 168.0)) { // validate hours throw new IllegalArgumentException(“Hours worked must be >= 0.0 and <= 168.0"); } this.wage = wage; this.hours = hours; } // set wage public void setWage(double wage) { if (wage < 0.0) // validate wage { xxxxx xxx xxxxxxxxxxxxxxxxxxxxxxxx("xxxxxx xxxx xxxx xx >= 0.0″);
}
xxxx.xxxx = xxxx;
}
Preview Invoice.java
xxxxxx xxxxxxx(xxxxxx xxxxxxxxxx, xxxxxx xxxxxxxxxxxxxxx, xxx xxxxxxxx, xxxxxx xxxxxxxxxxxx) {
xx (xxxxxxxx < 0) { // xxxxxxxx xxxxxxxx xxxxx xxx xxxxxxxxxxxxxxxxxxxxxxxx("xxxxxxxx xxxx xx >= 0″);
}
if (pricePerItem < 0.0) { // validate pricePerItem throw new IllegalArgumentException("Price per item must be >= 0″); }
this.quantity = quantity; this.partNumber = partNumber; this.partDescription = partDescription; this.pricePerItem = pricePerItem; }
// get part number public String getPartNumber() {return partNumber;}
// xxx xxxxxxxxxxx
xxxxxx xxxxxx xxxxxxxxxxxxxxxxxx() {xxxxxx xxxxxxxxxxxxxxx;}
// xxx xxxxxxxx
xxxxxx xxx xxxxxxxxxxx() {xxxxxx xxxxxxxx;}
Preview Payable.java
// Fig. 10.11: Payable.java // Payable interface declaration.
public interface Payable { public abstract double getPaymentAmount(); // no implementation
xxxxxx xxxxxxxx xxxxxx xxxxxxxxxxxxxxxx(); // xx xxxxxxxxxxxxxx
}
Preview PayableInterfaceTest.java
// xxx. 10.14: xxxxxxxxxxxxxxxxxxxx.xxxx
// xxxxxxx xxxxxxxxx xxxx xxxxxxx xxxxxxxxxx xxxxxxxx xxx
// xxxxxxxxx xxxxxxxxxxxxxxx.
xxxxxx xxxxx xxxxxxxxxxxxxxxxxxxx {
xxxxxx xxxxxx xxxx xxxx(xxxxxx[] xxxx) {
// create four-element Payable array Payable[] payableObjects = new Payable[] { new Invoice(“01234”, “seat”, 2, 375.00), new Invoice(“56789”, “tire”, 4, 79.95), new SalariedEmployee(“John”, “Smith”, “111-11-1111”, 800.00), new HourlyEmployee(“Lisa”, “Barnes”, “888-88-8888”, 16.75, 40.0), new CommissionEmployee(“Alan”, “Worker”, “222-22-2222”, 10000, .06),
xxx xxxxxxxxxxxxxxxxxxxxxxxxxx(“xxxxx”, “xxxxxx”, “555-55-55555”, 10000, .06, 300),
};
xxxxxx.xxx.xxxxxxx(“xxxxxxxx xxx xxxxxxxxx xxxxxxxxx xxxxxxxxxxxxxxx:”);
// xxxxxxxxxxx xxxxxxx xxxx xxxxxxx xx xxxxxxxxxxxxxxxxxxxx
Preview PayrollSystemTest.java
xxxxxx.xxx.xxxxxxx(“xxxxxxxxx xxxxxxxxx xxxxxxxxxxxx:”);
xxxxxx.xxx.xxxxxx(“%x%x%x%x: $%,.2x%x%x”,xxxxxxxxxxxxxxxx, “xxxxxx”,xxxxxxxxxxxxxxxx.xxxxxxxx());
xxxxxx.xxx.xxxxxx(“%x%x%x: $%,.2x%x%x”,
hourlyEmployee, “earned”, hourlyEmployee.earnings()); System.out.printf(“%s%n%s: $%,.2f%n%n”, commissionEmployee, “earned”, commissionEmployee.earnings()); System.out.printf(“%s%n%s: $%,.2f%n%n”, basePlusCommissionEmployee, “earned”, basePlusCommissionEmployee.earnings());
// create four-element Employee array Employee[] employees = new Employee[4];
// initialize array with Employees employees[0] = salariedEmployee; employees[1] = hourlyEmployee; employees[2] = commissionEmployee;
xxxxxxxxx[3] = xxxxxxxxxxxxxxxxxxxxxxxxxx;
xxxxxx.xxx.xxxxxx(“xxxxxxxxx xxxxxxxxx xxxxxxxxxxxxxxx: %x%x”);
// xxxxxxxxxxx xxxxxxx xxxx xxxxxxx xx xxxxx xxxxxxxxx
xxx (xxxxxxxx xxxxxxxxxxxxxxx : xxxxxxxxx) {
Preview SalariedEmployee.java
// xxx. 10.5: xxxxxxxxxxxxxxxx.xxxx
// xxxxxxxxxxxxxxxx xxxxxxxx xxxxx xxxxxxx xxxxxxxx xxxxx xxxxxxxx.
xxxxxx xxxxx xxxxxxxxxxxxxxxx xxxxxxx xxxxxxxx {
xxxxxxx xxxxxx xxxxxxxxxxxx;
// constructor public SalariedEmployee(String firstName, String lastName, String socialSecurityNumber, double weeklySalary) { super(firstName, lastName, socialSecurityNumber);
if (weeklySalary < 0.0) { throw new IllegalArgumentException("Weekly salary must be >= 0.0″);
}
xxxx.xxxxxxxxxxxx = xxxxxxxxxxxx;
}
// xxx xxxxxx
Preview BasePlusCommissionEmployee.java
xx (xxxxxxxxxx < 0.0) { // xxxxxxxx xxxxxxxxxx xxxxx xxx xxxxxxxxxxxxxxxxxxxxxxxx("xxxx xxxxxx xxxx xx >= 0.0″);
}
this.baseSalary = baseSalary; }
// set base salary public void setBaseSalary(double baseSalary) { if (baseSalary < 0.0) { // validate baseSalary throw new IllegalArgumentException("Base salary must be >= 0.0″); }
this.baseSalary = baseSalary; }
// xxxxxx xxxx xxxxxx
xxxxxx xxxxxx xxxxxxxxxxxxx() { xxxxxx xxxxxxxxxx;}
// xxxxxxxxx xxxxxxxx; xxxxxxxx xxxxxx xxxxxxxx xx xxxxxxxxxxxxxxxxxx
@xxxxxxxx
xxxxxx xxxxxx xxxxxxxx() {
Preview CommissionEmployee.java
xx (xxxxxxxxxxxxxx <= 0.0 || xxxxxxxxxxxxxx >= 1.0) // xxxxxxxx
{
xxxxx xxx xxxxxxxxxxxxxxxxxxxxxxxx(“xxxxxxxxxx xxxx xxxx xx > 0.0 xxx < 1.0"); } if (grossSales < 0.0) { // validate throw new IllegalArgumentException("Gross sales must be >= 0.0″); }
this.grossSales = grossSales; this.commissionRate = commissionRate; }
// set gross sales amount public void setGrossSales(double grossSales) { if (grossSales < 0.0) { // validate xxxxx xxx xxxxxxxxxxxxxxxxxxxxxxxx("xxxxx xxxxx xxxx xx >= 0.0″);
}
xxxx.xxxxxxxxxx = xxxxxxxxxx;
}
Preview Employee.java
// xxx. 10.13: xxxxxxxx.xxxx
// xxxxxxxx xxxxxxxx xxxxxxxxxx xxxx xxxxxxxxxx xxxxxxx.
xxxxxx xxxxxxxx xxxxx xxxxxxxx xxxxxxxxxx xxxxxxx {
xxxxxxx xxxxx xxxxxx xxxxxxxxx;
private final String lastName; private final String socialSecurityNumber;
// constructor public Employee(String firstName, String lastName, String socialSecurityNumber) { this.firstName = firstName; this.lastName = lastName;
xxxx.xxxxxxxxxxxxxxxxxxxx = xxxxxxxxxxxxxxxxxxxx;
}
// xxxxxx xxxxx xxxx
xxxxxx xxxxxx xxxxxxxxxxxx() {xxxxxx xxxxxxxxx;}
Preview HourlyEmployee.java
xx (xxxx < 0.0) // xxxxxxxx xxxx { xxxxx xxx xxxxxxxxxxxxxxxxxxxxxxxx("xxxxxx xxxx xxxx xx >= 0.0″);
}
if ((hours < 0.0) || (hours > 168.0)) { // validate hours throw new IllegalArgumentException(“Hours worked must be >= 0.0 and <= 168.0"); } this.wage = wage; this.hours = hours; } // set wage public void setWage(double wage) { if (wage < 0.0) // validate wage { xxxxx xxx xxxxxxxxxxxxxxxxxxxxxxxx("xxxxxx xxxx xxxx xx >= 0.0″);
}
xxxx.xxxx = xxxx;
}
Preview Invoice.java
xxxxxx xxxxxxx(xxxxxx xxxxxxxxxx, xxxxxx xxxxxxxxxxxxxxx, xxx xxxxxxxx, xxxxxx xxxxxxxxxxxx) {
xx (xxxxxxxx < 0) { // xxxxxxxx xxxxxxxx xxxxx xxx xxxxxxxxxxxxxxxxxxxxxxxx("xxxxxxxx xxxx xx >= 0″);
}
if (pricePerItem < 0.0) { // validate pricePerItem throw new IllegalArgumentException("Price per item must be >= 0″); }
this.quantity = quantity; this.partNumber = partNumber; this.partDescription = partDescription; this.pricePerItem = pricePerItem; }
// get part number public String getPartNumber() {return partNumber;}
// xxx xxxxxxxxxxx
xxxxxx xxxxxx xxxxxxxxxxxxxxxxxx() {xxxxxx xxxxxxxxxxxxxxx;}
// xxx xxxxxxxx
xxxxxx xxx xxxxxxxxxxx() {xxxxxx xxxxxxxx;}
Preview Payable.java
// Fig. 10.11: Payable.java // Payable interface declaration.
public interface Payable { public abstract double getPaymentAmount(); // no implementation
xxxxxx xxxxxxxx xxxxxx xxxxxxxxxxxxxxxx(); // xx xxxxxxxxxxxxxx
}
Preview PayableInterfaceTest.java
// xxx. 10.14: xxxxxxxxxxxxxxxxxxxx.xxxx
// xxxxxxx xxxxxxxxx xxxx xxxxxxx xxxxxxxxxx xxxxxxxx xxx
// xxxxxxxxx xxxxxxxxxxxxxxx.
xxxxxx xxxxx xxxxxxxxxxxxxxxxxxxx {
xxxxxx xxxxxx xxxx xxxx(xxxxxx[] xxxx) {
// create four-element Payable array Payable[] payableObjects = new Payable[] { new Invoice(“01234”, “seat”, 2, 375.00), new Invoice(“56789”, “tire”, 4, 79.95), new SalariedEmployee(“John”, “Smith”, “111-11-1111”, 800.00), new HourlyEmployee(“Lisa”, “Barnes”, “888-88-8888”, 16.75, 40.0), new CommissionEmployee(“Alan”, “Worker”, “222-22-2222”, 10000, .06),
xxx xxxxxxxxxxxxxxxxxxxxxxxxxx(“xxxxx”, “xxxxxx”, “555-55-55555”, 10000, .06, 300),
};
xxxxxx.xxx.xxxxxxx(“xxxxxxxx xxx xxxxxxxxx xxxxxxxxx xxxxxxxxxxxxxxx:”);
// xxxxxxxxxxx xxxxxxx xxxx xxxxxxx xx xxxxxxxxxxxxxxxxxxxx
Preview PayrollSystemTest.java
xxxxxx.xxx.xxxxxxx(“xxxxxxxxx xxxxxxxxx xxxxxxxxxxxx:”);
xxxxxx.xxx.xxxxxx(“%x%x%x%x: $%,.2x%x%x”,xxxxxxxxxxxxxxxx, “xxxxxx”,xxxxxxxxxxxxxxxx.xxxxxxxx());
xxxxxx.xxx.xxxxxx(“%x%x%x: $%,.2x%x%x”,
hourlyEmployee, “earned”, hourlyEmployee.earnings()); System.out.printf(“%s%n%s: $%,.2f%n%n”, commissionEmployee, “earned”, commissionEmployee.earnings()); System.out.printf(“%s%n%s: $%,.2f%n%n”, basePlusCommissionEmployee, “earned”, basePlusCommissionEmployee.earnings());
// create four-element Employee array Employee[] employees = new Employee[4];
// initialize array with Employees employees[0] = salariedEmployee; employees[1] = hourlyEmployee; employees[2] = commissionEmployee;
xxxxxxxxx[3] = xxxxxxxxxxxxxxxxxxxxxxxxxx;
xxxxxx.xxx.xxxxxx(“xxxxxxxxx xxxxxxxxx xxxxxxxxxxxxxxx: %x%x”);
// xxxxxxxxxxx xxxxxxx xxxx xxxxxxx xx xxxxx xxxxxxxxx
xxx (xxxxxxxx xxxxxxxxxxxxxxx : xxxxxxxxx) {
Preview SalariedEmployee.java
// xxx. 10.5: xxxxxxxxxxxxxxxx.xxxx
// xxxxxxxxxxxxxxxx xxxxxxxx xxxxx xxxxxxx xxxxxxxx xxxxx xxxxxxxx.
xxxxxx xxxxx xxxxxxxxxxxxxxxx xxxxxxx xxxxxxxx {
xxxxxxx xxxxxx xxxxxxxxxxxx;
// constructor public SalariedEmployee(String firstName, String lastName, String socialSecurityNumber, double weeklySalary) { super(firstName, lastName, socialSecurityNumber);
if (weeklySalary < 0.0) { throw new IllegalArgumentException("Weekly salary must be >= 0.0″);
}
xxxx.xxxxxxxxxxxx = xxxxxxxxxxxx;
}
// xxx xxxxxx
Price: $30
Buy Now
Checkout
Added to cart
Add to Cart
Checkout
Added to cart

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.