Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
26 changes: 26 additions & 0 deletions src/main/java/core/basesyntax/Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package core.basesyntax;

public class Calculator {
public double calculate(double firstValue, double secondValue, char operation) {
switch (operation) {
case '+':
return firstValue + secondValue;
case '-':
return firstValue - secondValue;
case '*':
return firstValue * secondValue;
case '/':
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Make constants for operations chars.

if (secondValue == 0) {
throw new ArithmeticException("can`t divide on 0");
}
return firstValue / secondValue;
case '^':
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