1. Start NetBeans.

2. Create a new project called YournameLab5

3. Write output statements that display the following menu of options:

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

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

5. 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 user's 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 user's choice was invalid.

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

Sample output 1:

Choose 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

Sample output 2:

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!

Sample output 3:

Choose 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

7. Put the code to display the menu, read the user's 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.

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

Choose 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!

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

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

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

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

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

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

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

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:
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

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

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

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

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

(d) 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.

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

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

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: 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

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

(a) Prompt the user to enter a number.

(b) Read an int.

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

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

(e) Display the result to the user.

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

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: 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

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

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

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.