Question: Java question Write a simple calculator program that takes input from the user to perform addition, subtraction, multiplication, and division. a)Write a method called prompt
Java question
Write a simple calculator program that takes input from the user to perform addition, subtraction, multiplication, and division.
a)Write a method called prompt that will print to output a prompt for the user, asking whether they want to perform (a)ddition, (s)ubtraction, (m)ultiplication, or (d)ivision, or else (q)uit the calculator. Your method should not take any parameters, but should use the Scanner class to take input from the user after giving the appropriate prompt. Your method should return a character that corresponds to the first character of the String given by the user as input. If it is a letter, the returned character should be lower case.
b)Write a method called intCalculator that will perform integer arithmetic on a set of values given by the user. Your method should take a single character as a parameter that should indicate whether addition, subtraction, multiplication, or division will be performed (a, s, m, or d, respectively). Your method should also print out a prompt indicating that the user should enter two integer values. 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.
c)Write a main method that uses the methods from parts (a) and (b) together to perform as many integer arithmetic operations as the user desires, until they enter q to quit. If the user enters something that does not correspond to one of the five characters indicated in the prompt (a, s, m, d, or q), then the program should print another prompt, and continue printing prompts until valid input is given. For example, a single run of the program should result in something similar to the following set of output prompts and input values from the user:
Do want to (a)dd, (s)ubtract, (m)ultiply, (d)ivide, or (q)uit?
add
Enter two integer values to add:
2 5
Your result is: 7
Do want to (a)dd, (s)ubtract, (m)ultiply, (d)ivide, or (q)uit?
d
Enter two integer values to divide:
13 2
Your result is: 6
Do want to (a)dd, (s)ubtract, (m)ultiply, (d)ivide, or (q)uit?
wuit
Do want to (a)dd, (s)ubtract, (m)ultiply, (d)ivide, or (q)uit?
q
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
