Question: need help with theses questions using these codes below netbeans import java.text.NumberFormat; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; import java.util.ArrayList; public class Invoice {

need help with theses questions using these codes below netbeans

need help with theses questions using these codes below netbeans \ import

\

java.text.NumberFormat; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; import java.util.ArrayList; public class Invoice

import java.text.NumberFormat; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; import java.util.ArrayList;

public class Invoice {

// the instance variables private ArrayList lineItems; private LocalDateTime invoiceDate; // the constructor public Invoice() { lineItems = new ArrayList(); invoiceDate = LocalDateTime.now(); }

public void addItem(LineItem lineItem) { lineItems.add(lineItem); }

public ArrayList getLineItems() { return lineItems; }

public double getTotal() { double invoiceTotal = 0; for (LineItem lineItem : lineItems) { invoiceTotal += lineItem.getTotal(); } return invoiceTotal; }

public String getTotalFormatted() { NumberFormat currency = NumberFormat.getCurrencyInstance(); return currency.format(getTotal()); } public void setInvoiceDate(LocalDateTime invoiceDate) { this.invoiceDate = invoiceDate; }

public LocalDateTime getInvoiceDate() { return invoiceDate; }

public String getInvoiceDateFormatted() { DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedDate( FormatStyle.SHORT); return dtf.format(invoiceDate); } }

import murach.db.ProductDB; import murach.business.Invoice; import murach.business.LineItem; import murach.business.Product;

public class InvoiceApp {

public static Invoice invoice = new Invoice();

public static void main(String args[]) { System.out.println("Welcome to the Invoice application "); getLineItems(); displayInvoice(); }

public static void getLineItems() { String choice = "y"; while (choice.equalsIgnoreCase("y")) { String productCode = Console.getString("Enter product code: "); int quantity = Console.getInt("Enter quantity: ");

Product product = ProductDB.getProduct(productCode); invoice.addItem(new LineItem(product, quantity));

choice = Console.getString("Another line item? (y): "); System.out.println(); } }

public static void displayInvoice() { StringBuilder sb = new StringBuilder(); sb.append("Invoice date: "); sb.append(invoice.getInvoiceDateFormatted()); sb.append(" "); sb.append(StringUtil.pad("Description", 34)); sb.append(StringUtil.pad("Price", 10)); sb.append(StringUtil.pad("Qty", 5)); sb.append(StringUtil.pad("Total", 10)); sb.append(" ");

for (LineItem lineItem : invoice.getLineItems()) { Product product = lineItem.getProduct(); sb.append(StringUtil.pad(product.getDescription(), 34)); sb.append(StringUtil.pad(product.getPriceFormatted(), 10)); sb.append(StringUtil.pad(lineItem.getQuantityFormatted(), 5)); sb.append(StringUtil.pad(lineItem.getTotalFormatted(), 10)); sb.append(" "); } sb.append(" Invoice total: "); sb.append(invoice.getTotalFormatted()); sb.append(" "); System.out.println(sb); } }

Exercise 14-1 Add a due date to the Invoice application For this exercise, you'll modify the Invoice class that's shown at the end of this chapter so it contains methods that return a due date, calculated as 30 days after the invoice date. 1. Open the project named ch14_ex1_Invoice that's in the ex_starts folder. Then, review the code in the Invoice and InvoiceApp classes. 2. In the Invoice class, modify the getInvoiceDateFormatted() method so it returns the due date using the MEDIUM format style. 3. In the Invoice class, add a method named getDueDate(). This method should calculate and return a LocalDate Time object that's 30 days after the invoice a date. 4. In the Invoice class, add a method named getDueDateFormatted(). This method should return the due date using the MEDIUM format style. 5. In the InvoiceApp class, modify the display Invoice() method so it displays the invoice date and the due date before it displays the line items like this: Invoice date: Apr 1, 2017 Invoice due date: May 1, 2017 Description Murach's Java Programming Price $57.50 Qty 2 Total $115.00 Invoice total: $115.00

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!