Question: You will write a calculator program that can handle basic arithmetic and basic trigonometric calculations on input values given by the user. There will be

You will write a calculator program that can handle basic arithmetic and basic trigonometric calculations on input values given by the user. There will be two menus of options given to the user: the first is a choice between performing arithmetic and trigonometry, and the second is choosing the specific arithmetic/trigonometric function they want to perform.

a) Write a method called arrayContains that takes a character array and a character value as parameters, and returns a boolean. Your method should determine whether the parameter character value exists within the parameter array, returning true if the character value exists, and false otherwise.

b) Write a method called doPrompt that takes a character array and a String as parameters, and returns a character. The parameter character array represents a set of valid character values, and the parameter String represents a prompt. Your method should print to output the prompt for the user, then use the Scanner class to take input from the user. Consider only the first character of the users input, and convert it to lower case. If the entered character is not within the array of valid character values, then continue prompting; otherwise, return the (valid, converted to lowercase) character entered by the user.

c) Write a method called arithCalculator that takes a single character parameter and has no return value. The character parameter represents the arithmetic operation that will be performed. Your method will perform floating point (double) arithmetic on a set of values given by the user, either addition, subtraction, multiplication, or division depending on whether the parameter character is a, s, m, or d, respectively.

All other character values will be ignored, and the resulting value will 0.0.. Your method should print out a prompt indicating that the user should enter two double values, then use the Scanner class to collect both values, and finally perform the appropriate arithmetic operation.

Your method should not return any value, but should print out the result of performing the indicated arithmetic operation on the two values given by the user, with an appropriate message.

d) Write a method called trigCalculator that takes a single character parameter and has no return value. The character parameter represents the trigonometric operation that will be performed. Your method will use the Math class to calculate one of the basic trig functions based on a single double value given by the user, either sin, cos, or tan depending on whether the parameter character is s, c, or t, respectively. All other character values will be ignored, and the resulting value will 0.0.. Your method should print out a prompt indicating that the user should enter one double value, then use the Scanner class to collect the value, and finally perform the appropriate trigonometric operation.

Your method should not return any value, but should print out the result of performing the indicated trigonometric operation on the single value given by the user, with an appropriate message.

Write a main method that uses the methods from parts (b), (c), and (d) together to perform as many operations as the user desires, until they enter q to quit. The user should first be prompted by a main menu to choose between (a)rithmetic, (t)rigonometry, or (q)uitting the program. If the user enters something that does not begin with one of these three valid characters, then they are continually prompted until they give valid input.

If they choose arithmetic, then the user should be prompted to choose between addition, subtraction, multiplication, or division. If the users inputted choice is not valid, then continue prompting until it is. Two double values are then read from the users input using the Scanner class, the indicated operation is performed, and the result printed to output. The user is then returned to the main menu selection.

If instead the user chooses trigonometry, then they should be prompted to choose between performing the sin, cos, or tan operation. If the users inputted choice is not valid, then continue prompting until it is. One double value is then read from the users input, the operation is performed, and the result printed to output. The user is then returned to the main menu selection.

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!