Question
How to i change the code below to get the output on the picture import java.util.Scanner; public class InvoiceApp { public static void main(String[] args)
How to i change the code below to get the output on the picture
import java.util.Scanner;
public class InvoiceApp {
public static void main(String[] args) {
// welcome the user to the program
System.out.println("Welcome to the Invoice Total Calculator");
System.out.println(); // print a blank line
System.out.println("Please enter the number of list items");
// create a Scanner object named sc
Scanner sc = new Scanner(System.in);
// initialize variables for use in calculating averages
double invoiceTotal = 0.0;
double discountTotal = 0.0;
int invoiceCount = 0;
String choice = "y";
while (!choice.equalsIgnoreCase("n")) {
System.out.print("Enter subtotal: ");
String input = sc.nextLine();
double subtotal = Double.parseDouble(input);
double discountPercent;
if (subtotal >= 500) {
discountPercent = .25;
} else if (subtotal >= 200) {
discountPercent = .2;
} else if (subtotal >= 100) {
discountPercent = .1;
} else {
discountPercent = 0.0;
}
double discountAmount = subtotal * discountPercent;
double total = subtotal - discountAmount;
invoiceTotal = invoiceTotal + total;
discountTotal = discountTotal + discountAmount;
invoiceCount = invoiceCount + 1;
String message = "Discount percent: " + discountPercent + " "
+ "Discount amount: " + discountAmount + " "
+ "Invoice total: " + total + " ";
System.out.println(message);
// see if the user wants to continue
System.out.print("Continue? (y): ");
choice = sc.nextLine();
System.out.println();
}
String message = "Number of invoices: " + invoiceCount + " "
+ "Average invoice: " + invoiceTotal / invoiceCount + " "
+ "Average discount: " + discountTotal / invoiceCount + " ";
System.out.println(message);
}
}
Welcome to the Invoice Total Calculator v2 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = Enter the number of line items: 3 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = Enter the \#1 line items: 100.55 Enter the \#2 line items: 35.3 Enter the \#3 line items: 1 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = Subtotal:Discountpercent:Discountamount:Invoicetotal:136.850.1013.69123.16Step 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