Calculator Application with Library 1.1.3
A simple library for performing basic arithmetic operations with application
Loading...
Searching...
No Matches
Calculator.java
Go to the documentation of this file.
1
7
13package com.ucoruh.calculator;
14
15import org.slf4j.LoggerFactory;
16
17import ch.qos.logback.classic.Logger;
25public class Calculator {
26
30 private static final Logger logger = (Logger) LoggerFactory.getLogger(Calculator.class);
31
41 public int add(int a, int b) {
42 logger.info("add({}, {})", a, b);
43 return a + b;
44 }
45
53 public int subtract(int a, int b) {
54 logger.info("subtract({}, {})", a, b);
55 return a - b;
56 }
57
65 public int multiply(int a, int b) {
66 logger.info("multiply({}, {})", a, b);
67 return a * b;
68 }
69
81 public double divide(int a, int b) {
82 logger.info("divide({}, {})", a, b);
83
84 if (b == 0) {
85 logger.error("divide by zero requested for dividend {}", a);
86 throw new ArithmeticException("Division by zero");
87 }
88
89 return (double) a / (double) b;
90 }
91}
This class represents a Calculator that performs mathematical operations.
double divide(int a, int b)
Divides one integer by another.
int multiply(int a, int b)
Calculates the product of two integers.
int add(int a, int b)
Calculates the sum of two integers.
int subtract(int a, int b)
Calculates the difference between two integers.