subject
Engineering, 18.02.2020 00:57 hrcatena

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!

ansver
Answers: 3

Another question on Engineering

question
Engineering, 03.07.2019 14:10
Amass of m 1.5 kg of steam is contained in a closed rigid container. initially the pressure and temperature of the steam are: p 1.5 mpa and t 240°c (superheated state), respectively. then the temperature drops to t2= 100°c as the result of heat transfer to the surroundings. determine: a) quality of the steam at the end of the process, b) heat transfer with the surroundings. for: p1.5 mpa and t 240°c: enthalpy of superheated vapour is 2900 kj/kg, specific volume of superheated vapour is 0. 1483 m/kg, while for t 100°c: enthalpy of saturated liquid water is 419kj/kg, specific volume of saturated liquid water is 0.001043m/kg, enthalpy of saturated vapour is 2676 kj/kg, specific volume of saturated vapour is 1.672 m/kg and pressure is 0.1 mpa.
Answers: 3
question
Engineering, 04.07.2019 03:10
What precautions should you take to prevent injuries when dealing with heavy loads?
Answers: 1
question
Engineering, 04.07.2019 18:10
Fluids at rest possess no flow energy. a)- true b)- false
Answers: 3
question
Engineering, 04.07.2019 18:10
During a steady flow process, the change of energy with respect to time is zero. a)- true b)- false
Answers: 2
You know the right answer?
Define a MathOp interface that has four methods for add, subtract, multiply, and divide. These metho...
Questions
question
Mathematics, 05.05.2020 22:36
Questions on the website: 13722362