Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Display Customer Invoices Report Console Welcome to the Customer Invoices Report

ID: 3568226 • Letter: D

Question

Display Customer Invoices Report

Console

Welcome to the Customer Invoices Report

frankjones@yahoo.com          10504M   11/18/04   $99.00

frankjones@yahoo.com          10501M   10/25/04   $59.50

johnsmith@hotmail.com         10505M   11/18/04   $297.50

johnsmith@hotmail.com         10500M   10/25/04   $495.00

seagreen@levi.com             10502M   10/25/04   $99.00

wendyk@warners.com            10503M   10/25/04   $112.00

Operation

This application connects to a database and displays a list of all customers and their invoices. Each line in this report includes the customer

Explanation / Answer

import java.text.NumberFormat; public class Invoice { private final String customerType; private final double subtotal; private double discountAmount; private double discountPercent; private double invoiceTotal; private String sCustomerType; public Invoice(String customerType, double subtotal){ this.customerType = customerType; this.subtotal = subtotal; } public void setDiscountPercent(double discountPercent){ if (customerType.equalsIgnoreCase("r")) { if (subtotal >= 500) discountPercent = .2; else if (subtotal >= 250 && subtotal < 500) discountPercent =.15; else if (subtotal >= 100 && subtotal < 250) discountPercent =.1; else if (subtotal < 100) discountPercent =.0; } else if (customerType.equalsIgnoreCase("c")) { discountPercent = .2; } else { discountPercent = .05; } } public double getDiscountPercent(){ return discountPercent; } public void setDiscountAmount(double discountAmount){ discountAmount = subtotal * (getDiscountPercent()); } public double getDiscountAmount(){ return discountAmount; } public void setInvoiceTotal(double invoiceTotal){ invoiceTotal = subtotal - (getDiscountAmount()); } public double getInvoiceTotal(){ return invoiceTotal; } public void setCustomerType(String sCustomerType){ sCustomerType = "Unknown"; if (customerType.equalsIgnoreCase("r")) sCustomerType = "Retail"; else if (customerType.equalsIgnoreCase("c")) sCustomerType = "College"; } public String getCustomerType(){ return sCustomerType; } public String getInvoice(){ NumberFormat currency = NumberFormat.getCurrencyInstance(); NumberFormat percent = NumberFormat.getPercentInstance(); sCustomerType = this.getCustomerType(); discountPercent = this.getDiscountPercent(); discountAmount = this.getDiscountAmount(); invoiceTotal = this.getInvoiceTotal(); // Create a string representation of the full invoice and return String invoice = ("Subtotal: " + currency.format(subtotal) + " " + "Customer type: " + sCustomerType + " " + "Discount percent: " + percent.format(discountPercent)+ " " + "Discount amount: " + currency.format(discountAmount)+ " " + "Total: " + currency.format(invoiceTotal) + " "); return invoice; } }