diff --git a/.gitignore b/.gitignore index 496ee2c..89e80a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,15 @@ -.DS_Store \ No newline at end of file +# Gradle +.gradle/ +build/ + +# IDEA +.idea/ +*.iml + +# Compiled classes +**/out/ +**/*.class + +# OS +.DS_Store +Thumbs.db diff --git a/LICENSE b/LICENSE index 5c824c2..1c77da5 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 Vinit Shahdeo +Copyright (c) 2025 Debora0Martins Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 306d108..9ac21a8 100644 --- a/README.md +++ b/README.md @@ -1,52 +1,27 @@ -
- Thank You -
- +Melhorias possíveis +- Adicionar testes unitários com JUnit. +- Empacotar como JAR executável. +- Adicionar Gradle Wrapper para rodar sem instalar Gradle. diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..df1ff49 --- /dev/null +++ b/build.gradle @@ -0,0 +1,15 @@ +plugins { + id 'application' +} + +group = 'com.github.debora0martins' +version = '1.0.0' + +repositories { + mavenCentral() +} + +application { + // For Gradle 7+: replace with mainClass.set('InteractiveCalculator') if needed + mainClass = 'InteractiveCalculator' +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..c875536 --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'hacktoberfast2025Java' \ No newline at end of file diff --git a/src/main/java/InteractiveCalculator.java b/src/main/java/InteractiveCalculator.java new file mode 100644 index 0000000..eb48ce2 --- /dev/null +++ b/src/main/java/InteractiveCalculator.java @@ -0,0 +1,46 @@ +import java.util.InputMismatchException; +import java.util.Scanner; + +public class InteractiveCalculator { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + System.out.println("=== Calculadora Interativa ==="); + + try { + System.out.print("Digite o primeiro número: "); + double a = scanner.nextDouble(); + + System.out.print("Digite o segundo número: "); + double b = scanner.nextDouble(); + + System.out.print("Escolha a operação (+, -, *, /): "); + char op = scanner.next().charAt(0); + + double result; + switch (op) { + case '+': result = a + b; break; + case '-': result = a - b; break; + case '*': result = a * b; break; + case '/': + if (b == 0) { + System.out.println("Erro: divisão por zero."); + scanner.close(); + return; + } else { + result = a / b; + } + break; + default: + System.out.println("Operação inválida."); + scanner.close(); + return; + } + + System.out.println("Resultado: " + result); + } catch (InputMismatchException e) { + System.out.println("Entrada inválida. Use números (ex.: 1.23)."); + } finally { + scanner.close(); + } + } +} \ No newline at end of file