BAEL-3506 (#8210)
* BAEL-3506 * BAEL-3506 * BAEL-3506 - Added java-math-2 to parent pom.
This commit is contained in:
parent
256c40aa3f
commit
8095153e25
|
@ -0,0 +1,8 @@
|
|||
## Java Math
|
||||
|
||||
This module contains articles about math in Java.
|
||||
|
||||
### Relevant articles:
|
||||
|
||||
- [Basic Calculator in Java](https://www.baeldung.com/basic-calculator-in-java)
|
||||
- More articles: [[<-- prev]](/../java-math)
|
|
@ -0,0 +1,105 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>java-math-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>java-math-2</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-math3</artifactId>
|
||||
<version>${commons-math3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ejml</groupId>
|
||||
<artifactId>ejml-all</artifactId>
|
||||
<version>${ejml.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.nd4j</groupId>
|
||||
<artifactId>nd4j-native</artifactId>
|
||||
<version>${nd4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.la4j</groupId>
|
||||
<artifactId>la4j</artifactId>
|
||||
<version>${la4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>colt</groupId>
|
||||
<artifactId>colt</artifactId>
|
||||
<version>${colt.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>${commons-codec.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${org.assertj.core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.dpaukov</groupId>
|
||||
<artifactId>combinatoricslib3</artifactId>
|
||||
<version>${combinatoricslib3.version}</version>
|
||||
</dependency>
|
||||
<!-- Benchmarking -->
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<commons-math3.version>3.6.1</commons-math3.version>
|
||||
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
||||
<commons-codec.version>1.11</commons-codec.version>
|
||||
<guava.version>27.0.1-jre</guava.version>
|
||||
<combinatoricslib3.version>3.3.0</combinatoricslib3.version>
|
||||
<ejml.version>0.38</ejml.version>
|
||||
<nd4j.version>1.0.0-beta4</nd4j.version>
|
||||
<colt.version>1.2.0</colt.version>
|
||||
<la4j.version>0.6.0</la4j.version>
|
||||
<jmh.version>1.19</jmh.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,55 @@
|
|||
package com.baeldung.maths.calculator.basic;
|
||||
|
||||
import java.util.InputMismatchException;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class BasicCalculatorIfElse {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
System.out.println("---------------------------------- \n" +
|
||||
"Welcome to Basic Calculator \n" +
|
||||
"----------------------------------");
|
||||
System.out.println("Following operations are supported : \n" +
|
||||
"1. Addition (+) \n" +
|
||||
"2. Subtraction (-) \n" +
|
||||
"3. Multiplication (* OR x) \n" +
|
||||
"4. Division (/) \n");
|
||||
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
try {
|
||||
System.out.println("Enter an operator: (+ OR - OR * OR /) ");
|
||||
char operation = scanner.next().charAt(0);
|
||||
|
||||
if (!(operation == '+' || operation == '-' || operation == '*' || operation == 'x' || operation == '/')) {
|
||||
System.err.println("Invalid Operator. Please use only + or - or * or /");
|
||||
}
|
||||
|
||||
System.out.println("Enter First Number: ");
|
||||
double num1 = scanner.nextDouble();
|
||||
|
||||
System.out.println("Enter Second Number: ");
|
||||
double num2 = scanner.nextDouble();
|
||||
|
||||
if (operation == '/' && num2 == 0.0) {
|
||||
System.err.println("Second Number cannot be zero for Division operation.");
|
||||
}
|
||||
|
||||
if (operation == '+') {
|
||||
System.out.println(num1 + " + " + num2 + " = " + (num1 + num2));
|
||||
} else if (operation == '-') {
|
||||
System.out.println(num1 + " - " + num2 + " = " + (num1 - num2));
|
||||
} else if (operation == '*' || operation == 'x') {
|
||||
System.out.println(num1 + " x " + num2 + " = " + (num1 * num2));
|
||||
} else if (operation == '/') {
|
||||
System.out.println(num1 + " / " + num2 + " = " + (num1 / num2));
|
||||
} else {
|
||||
System.err.println("Invalid Operator Specified.");
|
||||
}
|
||||
} catch (InputMismatchException exc) {
|
||||
System.err.println(exc.getMessage());
|
||||
} finally {
|
||||
scanner.close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package com.baeldung.maths.calculator.basic;
|
||||
|
||||
import java.util.InputMismatchException;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class BasicCalculatorSwitchCase {
|
||||
public static void main(String[] args) {
|
||||
|
||||
System.out.println("---------------------------------- \n"
|
||||
+ "Welcome to Basic Calculator \n"
|
||||
+ "----------------------------------");
|
||||
System.out.println("Following operations are supported : \n" +
|
||||
"1. Addition (+) \n" +
|
||||
"2. Subtraction (-) \n" +
|
||||
"3. Multiplication (* OR x) \n" +
|
||||
"4. Division (/) \n");
|
||||
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
try {
|
||||
System.out.println("Enter an operator: (+ OR - OR * OR /) ");
|
||||
char operation = scanner.next().charAt(0);
|
||||
|
||||
if (!(operation == '+' || operation == '-' || operation == '*' || operation == 'x' || operation == '/')) {
|
||||
System.err.println("Invalid Operator. Please use only + or - or * or /");
|
||||
}
|
||||
|
||||
System.out.println("Enter First Number: ");
|
||||
double num1 = scanner.nextDouble();
|
||||
|
||||
System.out.println("Enter Second Number: ");
|
||||
double num2 = scanner.nextDouble();
|
||||
|
||||
if (operation == '/' && num2 == 0.0) {
|
||||
System.err.println("Second Number cannot be zero for Division operation.");
|
||||
}
|
||||
|
||||
switch (operation) {
|
||||
case '+':
|
||||
System.out.println(num1 + " + " + num2 + " = " + (num1 + num2));
|
||||
break;
|
||||
case '-':
|
||||
System.out.println(num1 + " - " + num2 + " = " + (num1 - num2));
|
||||
break;
|
||||
case '*':
|
||||
System.out.println(num1 + " x " + num2 + " = " + (num1 * num2));
|
||||
break;
|
||||
case 'x':
|
||||
System.out.println(num1 + " x " + num2 + " = " + (num1 * num2));
|
||||
break;
|
||||
case '/':
|
||||
System.out.println(num1 + " / " + num2 + " = " + (num1 / num2));
|
||||
break;
|
||||
default:
|
||||
System.err.println("Invalid Operator Specified.");
|
||||
break;
|
||||
}
|
||||
} catch (InputMismatchException exc) {
|
||||
System.err.println(exc.getMessage());
|
||||
} finally {
|
||||
scanner.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
2
pom.xml
2
pom.xml
|
@ -508,6 +508,7 @@
|
|||
<!-- <module>java-ee-8-security-api</module> --> <!-- long running -->
|
||||
<module>java-lite</module>
|
||||
<module>java-math</module>
|
||||
<module>java-math-2</module> <!-- Added for BAEL-3506 -->
|
||||
<module>java-numbers</module>
|
||||
<module>java-numbers-2</module>
|
||||
<module>java-rmi</module>
|
||||
|
@ -1274,6 +1275,7 @@
|
|||
<module>java-ee-8-security-api</module>
|
||||
<module>java-lite</module>
|
||||
<module>java-math</module>
|
||||
<module>java-math-2</module> <!-- Added for BAEL-3506 -->
|
||||
<module>java-numbers</module>
|
||||
<module>java-numbers-2</module>
|
||||
<module>java-rmi</module>
|
||||
|
|
Loading…
Reference in New Issue