Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

package murach.ui; import java.util.Scanner; import murach.db.ProductDB; import murach.business.LineItem; import murach.business.Product; public class LineItemApp { public static void main(String args[]) { // display a welcome message

package murach.ui;

import java.util.Scanner;

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

public class LineItemApp {

public static void main(String args[]) { // display a welcome message System.out.println("Welcome to the Line Item Calculator"); System.out.println();

// create 1 or more line items Scanner sc = new Scanner(System.in); String choice = "y"; byte rcount = 0; float total = 0; float large = 0; float small = 99999; while (choice.equalsIgnoreCase("y")) { // get input from user System.out.print("Enter product code: "); String productCode = sc.nextLine();

System.out.print("Enter quantity: "); int quantity = Integer.parseInt(sc.nextLine()); // get the Product object Product product = ProductDB.getProduct(productCode);

// create the LineItem object LineItem lineItem = new LineItem(product, quantity);

// display the output String message = " LINE ITEM " + "Code: " + product.getCode() + " " + "Description: " + product.getDescription() + " " + "Price: " + product.getPriceFormatted() + " " + "Quantity: " + lineItem.getQuantity() + " " + "Total: " + lineItem.getTotalFormatted() + " "; System.out.println(message); total += product.getPrice() * quantity; rcount++;

// see if the user wants to continue System.out.print("Continue? (y/n): "); choice = sc.nextLine(); System.out.println(); } System.out.println("Number of line items: " + rcount); System.out.println("Invoice total: " + total); System.out.println("Bye!"); }

1. Run the application to make sure it runs properly.

2. Before the while loop, declare one variable of the float type that stores the largest line item and another variable of the float type that stores the smllest line item. After displaying the line item, use the max and min methods of the Math class to update the values for the largest and smallest line items. After the loop, display the total like this:

Largest line item: 172.5

Smallest line item: 100.0

3. To get this to work correctly, you need to initialize the minimum value to a very large value. Also, within the min and max methods of the Math class, you need to cast the value that's returned b the getTotal method of LineItem class to a float value.

4. Run the application again.

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

Step: 3

blur-text-image

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 Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions