Question
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!"); }
3. 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
4. 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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started