Question: Grading Rubric (for Instructions) YournameLab5.java Basics (25 pts, or -100 pts) File is named wrongly (You did not use your name ). (-100 pts, you

Grading Rubric (for Instructions)

YournameLab5.java

Basics (25 pts, or -100 pts)

File is named wrongly (You did not use your name). (-100 pts, you get 0 for this assignment, resubmit allowed, late penalty applies)

Student handed in wrong file. (-100 pts, you get 0, resubmission allowed, late penalty applies.)

Program code does not compile / run. (-50 pts, resubmission allowed, late penalty applies.)

Comments include student name, class, and description of assignment. (5 pts)

Declares a class with the correct class name. (5 pts)

Code is properly indented. (5 pts)

Main loop (25 pts)

Uses do-while loop. (5 pts)

Displays menu. (5 pts)

Reads input from user. (5 pts)

Uses a switch statement to determine the cases. (5 pts)

Exits loop if user chooses option 4. (5 pts)

Menu item 1: Perform an arithmetic operation (15 pts)

Reads expression from user. (5 pts)

Uses a switch statement to determine which operation to perform. (5 pts)

Performs the correct operation and displays the result. (5 pts)

Menu item 2: Apply a function (15 pts)

Reads function and argument from user. (5 pts)

Uses a switch statement to select the correct function. (5 pts)

Applies the correct function to the argument and displays the result. (5 pts)

Menu item 3: Calculate a factorial (10 pts)

Reads a number from the user. (5 pts)

Uses a while statement to calculate the factorial and displays the result. (5 pts)

Menu item 4: exit the program (5 pts)

Displays a thank-you message and exits the program using System.exit. (5 pts)

Displays an error message if user enters invalid menu option. (5 pts)

Instructions

Start NetBeans.

Create a new project called Lab5 with a main class called YournameLab5 with your name.

Write output statements that display the following menu of options:

one of the following options: 1. Perform an arithmetic operation 2. Apply a function 3. Calculate a factorial 4. Exit the program

Write an input statement that reads an integer from the user representing the option the user chose and store it in a varialbe.

Write a switch statement that uses this variable as a controlling expression and has cases for options 1-4 along with a default case.

For the cases for 1-3, display a string indicating the users choice and use a break statement to exit the switch statement.

For case 4, display a thank you message with your name and use System.exit to exit the program.

For the default case, display a message indicating the users choice was invalid.

Run your program to see if it works. Here are some examples of that the output should look like:

output 1:

one of the following options: 1. Perform an arithmetic operation 2. Apply a function 3. Calculate a factorial 4. Exit the program 1 Perform an arithmetic operation

output 2:

one of the following options: 1. Perform an arithmetic operation 2. Apply a function 3. Calculate a factorial 4. Exit the program 4 Thank you for using Edith Clarke's calculator!

output 3:

one of the following options: 1. Perform an arithmetic operation 2. Apply a function 3. Calculate a factorial 4. Exit the program 5 Invalid Choice

Put the code to display the menu, read the users choice, and the switch statement inside the body of a do-while loop. The loop should continue as long as the user did not choose 4.

Run your program to see if it works. Here is an example of what the output should look like:

one of the following options: 1. Perform an arithmetic operation 2. Apply a function 3. Calculate a factorial 4. Exit the program 0 Invalid Choice Choose one of the following options: 1. Perform an arithmetic operation 2. Apply a function 3. Calculate a factorial 4. Exit the program 2 Apply a function Choose one of the following options: 1. Perform an arithmetic operation 2. Apply a function 3. Calculate a factorial 4. Exit the program 4 Thank you for using Edith Clarke's calculator!

Replace the output statement in case 1 with code that does the following:

Prompt the user to enter an expression of the form NUM OP NUM.

Read an int representing the first number, a String representing the operation, and an int representing the second number.

Use the charAt method of the String class to extract the character as position 0 in the string and store it in a variable of type char.

Use a switch statement with the char variable as the controlling expression to determine the operator the user entered.

If the operator is one of +, -, *, /, %, perform the operation on the numbers the user entered and display the result.

For the default case, display an error indicating the user entered an unknown operator.

Run your program to see if it works. Here is an example of what the output should look like:

one of the following options: 1. Perform an arithmetic operation 2. Apply a function 3. Calculate a factorial 4. Exit the program 1 Enter an expression of the form NUM OP NUM: 7 ^ 2 Unknown operator: ^ Choose one of the following options: 1. Perform an arithmetic operation 2. Apply a function 3. Calculate a factorial 4. Exit the program 1 Enter an expression of the form NUM OP NUM: 8 / 2 Result: 4 Choose one of the following options: 1. Perform an arithmetic operation 2. Apply a function 3. Calculate a factorial 4. Exit the program 4 Thank you for using Edith Clarke's calculator

Replace the output statement in case 2 with code that does the following:

Prompt the user to enter an expression of the form FUNC ARG.

Read a String representing the function name, and a double representing the argument.

Use a switch statement with the String variable as the controlling expression to determine the function the user entered.

If the function is one of log, ln, or sqrt apply the function to the argument using the Math.log10, Math.log, or Math.sqrt methods respectively, and display the result.

For the default case, display an error indicating the user entered an unknown function.

Run your program to see if it works. Here is an example of what the output should look like:

one of the following options: 1. Perform an arithmetic operation 2. Apply a function 3. Calculate a factorial 4. Exit the program 2 Enter an expression of the form FUNC ARG: log .001 Result: -3.0 Choose one of the following options: 1. Perform an arithmetic operation 2. Apply a function 3. Calculate a factorial 4. Exit the program 2 Enter an expression of the form FUNC ARG: sin 0 Unrecognized function: sin Choose one of the following options: 1. Perform an arithmetic operation 2. Apply a function 3. Calculate a factorial 4. Exit the program 4 Thank you for using Edith Clarke's calculator

Replace the output statement in case 3 with code that does the following:

Prompt the user to enter a number.

Read an int.

Create a variable to store the result and initialize it to 1.

Use a while loop to multiply the result by every number between 1 and the number the user entered.

Display the result to the user.

Run your program to see if it works. Here is an example of what the output should look like:

one of the following options: 1. Perform an arithmetic operation 2. Apply a function 3. Calculate a factorial 4. Exit the program 3 Enter a number: 4 Result: 24 Choose one of the following options: 1. Perform an arithmetic operation 2. Apply a function 3. Calculate a factorial 4. Exit the program 3 Enter a number: -4 Result: 1 Choose one of the following options: 1. Perform an arithmetic operation 2. Apply a function 3. Calculate a factorial 4. Exit the program 4 Thank you for using Nicholas Coleman's calculator

Run your program again to make sure it works when each of the options is chosen.

Make sure your code is indented properly and you have CSCI 1011 Lab 5, your name, and a brief description of your program in the Javadoc comments before the class declaration.

Upload the file YournameLab5.java to the drop box folder labeled Lab Assignment 5.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!