Question

TULUI about stored within the JAR file, including the file that con AH excel the files that are stored within the JA the mainSection 1 Essential Java skills 12. When youre done inspecting the variables, click the Finish Debugger Session button to en

6-1 Test and debug the Invoice Application

i need help with this please.. all help is appreciated

Source code Java:

import java.util.Scanner;
import java.text.NumberFormat;

public class InvoiceApp {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String choice = "y";

while (!choice.equalsIgnoreCase("n")) {
// get the input from the user
System.out.print("Enter customer type (r/c): ");
String customerType = sc.next();
System.out.print("Enter subtotal: ");
double subtotal = sc.nextDouble();

// get the discount percent
double discountPercent = 0.0;
switch(customerType) {
case "r":
case "R":
if (subtotal < 100) {
discountPercent = 0.0;
} else if (subtotal >= 100 && subtotal < 250) {
discountPercent = .1;
} else if (subtotal >= 250) {
discountPercent = .2;
}
break;
case "c":
case "C":
if (subtotal < 250) {
discountPercent = .2;
} else if (subtotal >= 250) {
discountPercent = .3;
}
break;
default:
discountPercent = .1;
break;
}

// calculate the discount amount and round to 2 decimals
double discountAmount = subtotal * discountPercent;
discountAmount = Math.ceil(discountAmount * 100) / 100;

// calculate the total
double total = subtotal - discountAmount;

// format and display the results
NumberFormat currency = NumberFormat.getCurrencyInstance();
NumberFormat percent = NumberFormat.getPercentInstance();
System.out.println(
"Discount percent: " + percent.format(discountPercent) + "\n"
+ "Discount amount: " + currency.format(discountAmount) + "\n"
+ "Total: " + currency.format(total) + "\n");

// see if the user wants to continue
System.out.print("Continue? (y/n): ");
choice = sc.next();
System.out.println();
}
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I've added the debugged code below and boldened the modifications.

# If you have a query/issue with respect to the answer, please drop a comment. I will surely try to address your query ASAP and resolve the issue

# # Please consider providing a thumbs up to this question if it helps you. by doing that, you will help other students who are facing a similar issue.

//----------------------------OUTPUT---------------------------------------------

Enter customer type (1/c): I Enter subtotal: $1000 Exception in thread main java.util.Input MismatchException at java.base/

---- OUTPUT with debugged code ------

Enter customer type (1/c): I Enter subtotal: 1000$ Error! Invalid number.Try again. Enter customer type (1/c): C Enter subtot

//-------------------------------------------------------------------------


import java.util.InputMismatchException;

import java.util.Scanner;

import java.text.NumberFormat;

public class InvoiceApp {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String choice = "y";

        while (!choice.equalsIgnoreCase("n")) {

            // get the input from the user

            System.out.print("Enter customer type (r/c): ");

            String customerType = sc.next();

            double subtotal = 0.0;

            // try block for exception

            try {

                // prompts the user and takes input

                System.out.print("Enter subtotal: ");

                subtotal = sc.nextDouble();

            } catch (InputMismatchException e) {

                // reads and discards the invaid string

                sc.next();

                System.out.println("Error! Invalid number.Try again.\n");

                // start the loop again

                continue;

            }

            // get the discount percent

            double discountPercent = 0.0;

            switch (customerType) {

            case "r":

            case "R":

                if (subtotal < 100) {

                    discountPercent = 0.0;

                } else if (subtotal >= 100 && subtotal < 250) {

                    discountPercent = .1;

                } else if (subtotal >= 250) {

                    discountPercent = .2;

                }

                break;

            case "c":

            case "C":

                if (subtotal < 250) {

                    discountPercent = .2;

                } else if (subtotal >= 250) {

                    discountPercent = .3;

                }

                break;

            default:

                discountPercent = .1;

                break;

            }

            // calculate the discount amount and round to 2 decimals

            double discountAmount = subtotal * discountPercent;

            discountAmount = Math.ceil(discountAmount * 100) / 100;

            // calculate the total

            double total = subtotal - discountAmount;

            // format and display the results

            NumberFormat currency = NumberFormat.getCurrencyInstance();

            NumberFormat percent = NumberFormat.getPercentInstance();

            System.out.println("Discount percent: " + percent.format(discountPercent) + "\n" + "Discount amount: "

                    + currency.format(discountAmount) + "\n" + "Total: " + currency.format(total) + "\n");

            // see if the user wants to continue

            System.out.print("Continue? (y/n): ");

            choice = sc.next();

            System.out.println();

        }

    }

}

//---------------------------------------------------------------

Add a comment
Know the answer?
Add Answer to:
6-1 Test and debug the Invoice Application i need help with this please.. all help is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ; I'm having an issue editing the code. Could you please edit the code as the tutorial states and past the console o...

    ; I'm having an issue editing the code. Could you please edit the code as the tutorial states and past the console output. Here is the link. https://docs.microsoft.com/en-us/visualstudio/debugger/quickstart-debug-with-cplusplus?view=vs-2017 Exercise 1: Visual Studio Debugger https://docs.microsoft.com/en-us/visualstudio/debugger/quickstart-debug-with- cplusplus?view=vs-2017 Complete the tutorial. Include the console output of the sample console program after editing the code while debugging. The green Continue toolbar button can be used to continue executing code after pausing from a breakpoint. Instead of pressing F10, you can "Step Over" code using...

  • The Murach's Visual Basic 2015 Book And Visual Studio Exercise 7-2 Enhance the Invoice Total application...

    The Murach's Visual Basic 2015 Book And Visual Studio Exercise 7-2 Enhance the Invoice Total application If you did exercise 6-1 in the last chapter, this exercise asks you to add data validation and exception handling to it. 1. Copy the Invoice Total application from your C:\VB 2015\Chapter 06 directory to your Chapter 07 directory. This should be your solution to exercise 6-1 of the last chapter. 2. If your application has both a Sub procedure and a Function procedure...

  • Please help me code the following in JAVA! Box class: Debugme class: (1) Debug the two...

    Please help me code the following in JAVA! Box class: Debugme class: (1) Debug the two programs (DebugMe.java and Box.java) by following the comments and fixing the errors. Note that there are both syntax and logic errors. (2) We'll use the graphical debugger built into Eclipse a. Set a breakpoint on the first line in main i. Do this by clicking in the "gutter" area for Eclipse and Bluel. ii. These appear as blue circles in Eclipse and red stop...

  • Murach's C# 2015 Training & Reference: I need help with both Exercise 4-1. I figured out...

    Murach's C# 2015 Training & Reference: I need help with both Exercise 4-1. I figured out steps 1-4, but not understanding how to modify the code for 5 & 6. Code is: private void btnCalculate_Click(object sender, EventArgs e)        {            decimal subtotal = Convert.ToDecimal(txtSubtotal.Text);            decimal discountPercent = .25m;            decimal discountAmount = subtotal * discountPercent;            decimal invoiceTotal = subtotal - discountAmount;            txtDiscountPercent.Text = discountPercent.ToString("p1");   ...

  • No matter which editor you’re using, there are debugging tools that can help simplify the process...

    No matter which editor you’re using, there are debugging tools that can help simplify the process of hunting down logic errors. In Eclipse and BlueJ, you just need to toggle a breakpoint in the gutter of the text area; this should place a blue circle next to the line of code your debugger will execute up to. Then to debug, instead of play, click on the “little bug” icon next to play. Say yes to the perspective change dialog, and...

  • This exercise guides you through the process of converting an Area and Perimeter application from a...

    This exercise guides you through the process of converting an Area and Perimeter application from a procedural application to an object-oriented application. Create and use an object 1. Open the project named ch04_ex2_Area and Perimeter that’s stored in the ex_starts folder. Then, review the code for the Main class. 2. Create a class named Rectangle and store it in the murach.rectangle package. 3. In the Rectangle class, add instance variables for length and width. The, code the get and set...

  • An application contains the Structure statement shown here. Structure MyFriend Public strName As String Public strBirthday...

    An application contains the Structure statement shown here. Structure MyFriend Public strName As String Public strBirthday As String End Structure Create a VB.Net Windows Form application named MyFriend_YourName. Change the name property of your form to frmMain. Add the MyFriend Structure to the public class frmMain. Create 2 text boxes txtName and txtBirthday, and a button with the name property changed to btnExecute and the text property changed to Execute. In the button click event, write a Dim statement that...

  • public static void main(String[] args) {         System.out.println("Welcome to the Future Value Calculator\n");         Scanner sc...

    public static void main(String[] args) {         System.out.println("Welcome to the Future Value Calculator\n");         Scanner sc = new Scanner(System.in);         String choice = "y";         while (choice.equalsIgnoreCase("y")) {             // get the input from the user             System.out.println("DATA ENTRY");             double monthlyInvestment = getDoubleWithinRange(sc,                     "Enter monthly investment: ", 0, 1000);             double interestRate = getDoubleWithinRange(sc,                     "Enter yearly interest rate: ", 0, 30);             int years = getIntWithinRange(sc,                     "Enter number of years: ", 0, 100);             System.out.println();            ...

  • please help me debug this Create a Future Value Calculator that displays error messages in labels.GUISpecificationsStart...

    please help me debug this Create a Future Value Calculator that displays error messages in labels.GUISpecificationsStart with the JavaFX version of the Future Value application presented in chapter 17. Create error message labels for each text field that accepts user input. Use the Validation class from chapter 17 to validate user input.Format the application so that the controls don’t change position when error messages are displayed. package murach.business; public class Calculation {        public static final int MONTHS_IN_YEAR =...

  • 1. Need help with a Java application that will compute tip amounts based on user input....

    1. Need help with a Java application that will compute tip amounts based on user input. Please let me know what else my code could use. My code is below and I need help formatting the output and calculating the amount paid by each person. Your application will: ask the user for a restaurant name, a waiter/waitress name, a bill amount and the number of people splitting the bill calculate 10%, 15% and 20% tips on the bill amount calculate...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT