Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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.16

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

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

=+ (a) Show that D is finitely but not countably additive on 9.

Answered: 1 week ago

Question

1. Define and explain culture and its impact on your communication

Answered: 1 week ago