Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CODE IN JAVA PLEASE READ QUESTIONS AND FOLLOW THE GIVEN CODES Commission.java public class Commission extends Employee { protected double grossSales; // gross sales protected

CODE IN JAVA

PLEASE READ QUESTIONS AND FOLLOW THE GIVEN CODES

image text in transcribedimage text in transcribed

Commission.java

public class Commission extends Employee {

protected double grossSales; // gross sales

protected double commissionRate; // rate of commission

/**

* Constructs a commissioned employee with specified name, sin, gross sales

* and commission rate

*

* @param name name of employee

* @param sin social insurance number of employee

* @param sales gross sales made by employee

* @param rate commission rate of employee

*/

public Commission(String name, String sin,

double sales, double rate) {

super(name, sin);

this.grossSales = sales;

this.commissionRate = rate;

}

/**

* Constructs a default commissioned employee

*/

public Commission() { // *note: implicit call to super()

this.grossSales = 0.0;

this.commissionRate = 0.0;

}

/**

* Gets the commissioned employee's amount of pay

*

* @return returns the payment amount of this commissioned employee

*/

@Override

public double getPaymentAmount() {

return commissionRate * grossSales;

}

}

Invoice.java

public class Invoice implements Payable {

private String invoiceNumber; // invoice number

private int quantity; // quantity of items

private double pricePerItem; // price per item

/**

* Constructs an invoice with specified invoice number, quantity and price

* per item

*

* @param number invoice number

* @param count quantity of items

* @param price price per item

*/

public Invoice(String number, int count,

double price) {

invoiceNumber = number;

quantity = count;

pricePerItem = price;

}

/**

* Constructs an invoice with default values

*/

public Invoice() { // use of this keyword to call constructor

this("unknown", 0, 0.0);

}

/**

* Gets the payment amount of the invoice

*

* @return returns the invoice payment amount

*/

public double getPaymentAmount() {

return quantity * pricePerItem;

}

/**

* Produces a string representation of an invoice

*

* @return textual representation of the invoice

*/

public String toString() {

return "Invoice# " + invoiceNumber + ": $" + String.format("%.2f", getPaymentAmount());

}

}

Lab2_Driver.java

import java.util.*;

public class Lab2_Driver {

public static void main(String[] args) {

ArrayList employees = new ArrayList();

employees.add(new Commission("Harry", "107", 5310.95, 0.23));

employees.add(new BasePlusCommission("James", "777", 450.00, 0.1, 4503.48));

employees.add(new Salaried("Melanie", "123", 1927.32));

employees.add(new Hourly("Trump", "666", 14.82, 40));

Invoice i1 = new Invoice("3111", 4, 199.99);

Invoice i2 = new Invoice("3112", 12, 25.35);

PayWeek thisweek = new PayWeek("January 21, 2022");

// add invoice payments and only commissioned employees to pay week

thisweek.addPayment(i1);

thisweek.addPayment(i2);

for (Employee e : employees) {

if (e instanceof Commission) {

thisweek.addPayment(e);

}

}

System.out.println(thisweek);

}

}

PayWeek.java

import java.util.ArrayList;

public class PayWeek {

private String weekEnding; // last day of pay week

private ArrayList payments; // list of payable items

/**

* Constructs a pay week with specified week ending date as String

*

* @param weekEnding last day of pay week

*/

public PayWeek(String weekEnding) {

this.weekEnding = weekEnding;

payments = new ArrayList();

}

/**

* Adds new payment to the payable list

*

* @param payment item

*/

public void addPayment(Payable p) {

payments.add(p);

}

/**

* Produces a string representation of a pay week, including all payable

* items

*

* @return textual representation of a pay week

*/

@Override

public String toString() {

StringBuilder sb = new StringBuilder();

sb.append("Payments for the week ending " + weekEnding + ": ");

for (Payable p : payments) {

sb.append(p + " ");

}

return sb.toString();

}

}

Refer to the following class diagram: > Payable 1 includes PayWeek String weekEnding + double getPaymentAmount() Invoice String partNumber int quantity double pricePerltem > Employee String name - String sin Salaried Commission Hourly - double wage - double hours - double grossSales - double commission Rate double weeklySalary BasePlus Commission double baseSalary a) In the Employee hierarchy, create the classes for Employee, Salaried, Hourly, and BasePlusCommission. Although not required in the driver, include no-arg constructors for ALL classes. Otherwise include all/only the necessary methods for the program. The following calculations for get PaymentAmount are used: Commission: grossSales * commission Rate BasePlusCommission: baseSalary + grossSales * commission Rate * b) Create the Payable interface. Add any details to the applicable classes in (a) for the implementation. In this company, commissioned employees are paid weekly while salary/hourly employees get paid biweekly. The week ending January 21, 2022 is a week where only commissioned employees get paid. Note that Lab2 Driver creates a) instances of all employee types (and adds them to an ArrayList) b) two invoices c) a Payweek object for the week ending January 21 and adds applicable employees and the given invoices. Sample output: Payments for the week ending January 21, 2022: Invoice# 3111: $799.96 Invoice# 3112: $304.20 Employee# 107: $1221.52 Employee# 777: $900.35

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

Database Processing Fundamentals Design

Authors: Marion Donnie Dutton Don F. Seaman

14th Edition Globel Edition

1292107634, 978-1292107639

More Books

Students also viewed these Databases questions

Question

What is conservative approach ?

Answered: 1 week ago

Question

What are the basic financial decisions ?

Answered: 1 week ago