[Exercise] Simple Calculator using Interfaces


Submit solution

Points: 10
Time limit: 0.5s
Memory limit: 2M

Author:
Problem type
Allowed languages
Java

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
86.0
72.0
Sample Output 1
Addition: 158.0
Subtraction: 14.0
Multiplication: 6192.0
Division: 1.1944444444444444
Sample Input 2
26.0
0.0
Sample Output 2
Addition: 26.0
Subtraction: 26.0
Multiplication: 0.0
Division by zero error!
Division: -1.0

Comments

There are no comments at the moment.