Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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_2

Step: 3

blur-text-image_3

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

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions