Language:EN
Pages: 11
Words: 1275
Rating : ⭐⭐⭐⭐⭐
Price: $10.99
Page 1 Preview
desc prints the menupublic static void printmenu p

Try-Catch Blocks Handling Exceptions Assignment Answers Needed

Your Question:

PLS CHECK THE CODE FOR ME. WHERE DOES THE TRY-CATCH BLOCK GO? THE QUESTION IS BELOW AND THE CODE IS AFTER THE QUESTION. THANK YOU.

Task 2

Run your new Maven application (App.java) and make sure it works.

If you can't recall how to create a Maven project properly, simply review the previous "Hello World with Maven" assignment which contains detailed instructions on Maven and example videos for students.

Write code to print the menu (without any of the actual commands actually functioning).

Edit your code by making small incremental changes.

Get the q command to work and display the values of A and B in the menu.

Edit your code by making small incremental changes.

Get the a and b commands to work.

Edit your code by making small incremental changes.

Get + and - to work. Git commit it, then Git push it.

Edit your code by making small incremental changes.

If you have more time, add the user error handling to create resilience in your application.

Make sure your data is stored in your variables as you expect using the debugger.

The display precision of A and B is 3 significant digits.

For example, the value of pi which is 3.14159 would be displayed as 3.142. The mantissa 142 is 3 significant digits.

/*

* chavvi calc calculator

Character command = '_';

try {

}catch(InputMismatchException e) {

System.out.println("ERROR: Invalid input. Please enter a valid number for A.");

printMenu();

// System.out.print("A: %d\n", A);

}

scan.close();

private static void printMenuLine() {

System.out.println(

System.out.printf("%s\t%s\n", command, desc);

}

printMenuLine();

printMenuCommand('q', "Quit");

// Add more menu items for other operations as needed

printMenuLine();

String rawInput = scan.nextLine();

if (rawInput.length() > 0) {

}

// calculator functions

System.out.println("Thank you for using Chavvi Calc");

break;

case 'b':

System.out.printf("B = %.3f\n", b); // Replace 'b' with the actual variable holding

double addValue = scan.nextDouble();

a += addValue; // Add the input value to A

double subtractValue = scan.nextDouble();

a -= subtractValue; // Subtract the input value from A

}

return success;

Step By Step Answers with Explanation

  1. NoSuchElementException: This exception can occur when attempting to read the next line of input if the user has not entered any input for the command in the menuGetCommand() function.

Here's how you can add try-catch blocks to handle these exceptions:

        Scanner scan = new Scanner(System.in);

        Character command = '_';

            System.out.printf("A set to %.3f%n", a);

        } catch (InputMismatchException e) {

        while (command != 'q') {

            printMenu();

            } catch (NoSuchElementException e) {

                System.out.println("ERROR: No command entered.");

    // ... Rest of the code (menu functions and calculator functions) ...

}

Top of Form

Bottom of Form

You are viewing 1/3rd of the document.Purchase the document to get full access instantly

Immediately available after payment
Both online and downloadable
No strings attached
How It Works
Login account
Login Your Account
Place in cart
Add to Cart
send in the money
Make payment
Document download
Download File
img

Uploaded by : Jesus Lutz

PageId: ELI4993841