[Exercise] Simple Calculator using Interfaces
Submit solution
Java
Points:
10
Time limit:
0.5s
Memory limit:
2M
Author:
Problem type
Allowed languages
Problem Definition
Define interface Calculator with functions like add, subtract, multiply, and divide.
Define Class BasicCalculator that implements interface Calculator.
Define Class BasicCalculatorExample that instantiates object for BasicCalculator* and uses the operations.
Assume the parameters for all operations and return type is double.
Error condition for division should be taken care.
Test Data
Sample Input 1
Copy
86.0
72.0
Sample Output 1
Copy
Addition: 158.0
Subtraction: 14.0
Multiplication: 6192.0
Division: 1.1944444444444444
Sample Input 2
Copy
26.0
0.0
Sample Output 2
Copy
Addition: 26.0
Subtraction: 26.0
Multiplication: 0.0
Division by zero error!
Division: -1.0
Comments