Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
9 changes: 2 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,10 @@
<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-RC1</version>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RC means Release Candidate, it could be not stable, try to avoid using RC versions

<scope>test</scope>
</dependency>

</dependencies>
<build>
<plugins>
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 (secondValue == Double.MIN_VALUE) {
throw new IllegalValueException("can`t resolve operation");
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this Exception? Raising with MIN_VALUE is corectly work, as with ZERO.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it return NuN not 0. Look at this screen ->
https://prnt.sc/1s5kqe1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

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