Question: Write a method called char randOperator() that will return a random arithmetic operator. The possible operators returned are: +, -, *, /, and %. The

Write a method called char randOperator() that will return a random arithmetic operator. The possible operators returned are: +, -, *, /, and %. The operators are just characters: '+', '-', '*', '/', and '%'. To generate a random operator, you generate a random number between 0 and 4. You can use a switch statement to return the operator character based on the integer value. For example, if the random number is 0, the method returns '+'. Here's the possible mapping of the integer value to operators: 0->'+', 1-> '-', 2->'*', 3-> '/', 4->'%'.

Write a method called int compute (char op, int first, int second) that computes the operation on the first and second operand and returns the result. For example, if op is '+', then it would return value of first + second. Hint: use switch statement.

In your main method, prompts the user for the number of expressions. Use a for loop prints random arithmetic expressions and their answers. The operands are random integers between 1 and 100.

Sample run:

How many problems? 10

87 % 66 = 21

81 % 51 = 30

47 / 70 = 0

47 * 57 = 2679

87 % 76 = 11

45 / 51 = 0

27 * 31 = 837

70 % 20 = 10

43 * 18 = 774

53 + 48 = 101

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 Programming Questions!