Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1.Start NetBeans. 2.Create a new project called Lab5 with a main class called YournameLab5 with your name. 3.Write output statements that display the following menu

1.Start NetBeans.

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

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

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:

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

Thank you for using (insert name) 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

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

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 (insert name) 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 thefirst 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 0 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.

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

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 (insert name) calculator

Replace the out

put 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, orsqrtapply the function to the argument using theMath.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 shouldlook 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 (insert name) 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 thenumber 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

Thank you for using (insert name) calculator

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

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions

Question

Understand why succession management is important.

Answered: 1 week ago