Practice composition by building a small business-domain model where an Invoice has-a Customer. Your code should safely handle a missing customer using a sentinel value.
null safelyname and emailgetName(), getEmail()getContactCard() that returns something like:
"Ada Lovelace <ada@company.com>" public class Customer{ // TODO: private instance variables (name, email)
// TODO: constructor(s)
// TODO: getters (getName, getEmail)
// TODO: getContactCard() -> returns a single formatted String}invoiceNumber, amount, paid, and customercustomer field may start as nullsetCustomer and clearCustomergetCustomerName():
"none" if customer is nullmarkPaid() to set the invoice status to paidgetSummary() that returns a single-line String summary exactly like the sample output format:
Invoice #____ | Customer: ____ | Amount: $____ | Status: ____ public class Invoice{ // TODO: private instance variables // invoiceNumber (int), amount (double), paid (boolean), customer (Customer)
// TODO: constructor // Hint: invoices begin unpaid, and customer may be null
// TODO: getters (getInvoiceNumber, getAmount, isPaid)
// TODO: composition methods // setCustomer(Customer customer) // clearCustomer() // getCustomerName() -> returns "none" if customer is null (sentinel)
// TODO: behavior methods // markPaid() // getSummary() -> returns a single formatted String describing the invoice}Customer: none)public class Program{ public static void main(String[] args) { // TODO: Create: // 1) an Invoice with no Customer yet // 2) a Customer // 3) assign the Customer to the Invoice // 4) mark the Invoice paid // 5) print invoice summaries at each stage (see Sample Output) }}-- Invoice Demo --
Invoice #1001 | Customer: none | Amount: $199.99 | Status: UNPAID
Assigning customer...Invoice #1001 | Customer: Ada Lovelace | Amount: $199.99 | Status: UNPAID
Marking invoice paid...Invoice #1001 | Customer: Ada Lovelace | Amount: $199.99 | Status: PAID