Commit 14cb0bb6 authored by Victor Guerra Veloso's avatar Victor Guerra Veloso

Arquivos iniciais do workshop

parents
import java.util.Scanner;
public class Calculadora {
private Operacao[] operacao;
public Calculadora() {
operacao = new Operacao[7];
operacao[0] = new OperacaoSoma();
operacao[1] = new OperacaoSub();
operacao[2] = new OperacaoMult();
operacao[3] = new OperacaoDiv();
operacao[4] = new OperacaoPot();
operacao[5] = new OperacaoRaiz();
operacao[6] = new OperacaoLog();
}
public Operacao[] getOperacao() {
return operacao;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Calculadora calc = new Calculadora();
int entrada = 0;
double x = 0;
double y = 0;
System.out.println("Olá usuário!");
System.out.println("Bem vindo a calculadora do minicurso!");
while (true) {
System.out.println("Escolha uma operação ou digite 0 para sair:");
System.out.println("1- Soma; 2- Subtração; 3- Multiplicação; 4- Divisão; 5- Potẽncia; 6- Raiz, 7- Logarítmo");
entrada = sc.nextInt();
if (entrada == 0) {
break;
}
System.out.print("Digite o valor de x:");
x = sc.nextDouble();
System.out.print("Digite o valor de y:");
y = sc.nextDouble();
System.out.println("Resposta: " + calc.getOperacao()[entrada - 1].opera(x, y));
}
}
}
\ No newline at end of file
public interface Operacao {
public double opera(double x, double y);
}
import java.lang.Math;
public class OperacaoLog implements Operacao {
@Override
public double opera(double x, double y) {
return Math.log(x) / Math.log(y);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment