Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<version>5.8.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/core/basesyntax/Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package core.basesyntax;

public class Calculator {
private static final char ADDITION_OPERATOR = '+';
private static final char SUBTRACTION_OPERATOR = '-';
private static final char MULTIPLICATION_OPERATOR = '*';
private static final char DIVISION_OPERATOR = '/';
private static final char RAISING_TO_POWER_OPERATOR = '^';

public double calculate(double firstValue, double secondValue, char operation) {
switch (operation) {
case ADDITION_OPERATOR:
return firstValue + secondValue;
case SUBTRACTION_OPERATOR:
return firstValue - secondValue;
case MULTIPLICATION_OPERATOR:
return firstValue * secondValue;
case DIVISION_OPERATOR:
if (secondValue == 0) {
throw new ArithmeticException("can`t divide on 0");
}
return firstValue / secondValue;
case RAISING_TO_POWER_OPERATOR:
if (firstValue < 0 && secondValue == Double.MIN_VALUE) {
throw new IllegalValueException("can`t resolve operation");
}
return Math.pow(firstValue, secondValue);
default:
throw new IllegalOperatorException("can't recognise operator, try again");
}
}
}
8 changes: 0 additions & 8 deletions src/main/java/core/basesyntax/HelloWorld.java

This file was deleted.

7 changes: 7 additions & 0 deletions src/main/java/core/basesyntax/IllegalOperatorException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package core.basesyntax;

public class IllegalOperatorException extends RuntimeException {
public IllegalOperatorException(String message) {
super(message);
}
}
7 changes: 7 additions & 0 deletions src/main/java/core/basesyntax/IllegalValueException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package core.basesyntax;

public class IllegalValueException extends RuntimeException {
public IllegalValueException(String message) {
super(message);
}
}
Loading