Question: Interface Define a MathOp interface that has four methods for add , subtract , multiply , and divide . These methods only work with integers

Interface

Define a MathOp interface that has four methods for add, subtract, multiply, and divide. These methods only work with integers.

Implementation

You will write a class that implements MathOp to support arithmetic operations. Each method should have two parameters. The divide method will throw an exception if the divisor is 0.

Write a program that uses the interface and implementation to allow the users to perform some arithmetic.

Sample run (text marked as bold are user inputs):

run:

1)add, 2)sub, 3)multiply, 4) divide, 5) exit:1 Enter operands:2 4 6 1)add, 2)sub, 3)multiply, 4) divide, 5) exit:2 Enter operands:4 2 2 1)add, 2)sub, 3)multiply, 4) divide, 5) exit:3 Enter operands:2 3 6 1)add, 2)sub, 3)multiply, 4) divide, 5) exit:4 Enter operands:3 2 1 1)add, 2)sub, 3)multiply, 4) divide, 5) exit:4 Enter operands:2 1 2 1)add, 2)sub, 3)multiply, 4) divide, 5) exit:4 Enter operands:3 0 Division by zero error! 1)add, 2)sub, 3)multiply, 4) divide, 5) exit:5 Bye!

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!