I'm having a lot of problems regarding a job to be delivered tomorrow, can anyone help?
EDIT: I made the base, but I'm having trouble adding the switch to the code and completing the calculator, can you tell me how to do at least the add and insert part of the number? would it be with a scanner?
Build a Java Calculator that has the following features:
Menu: (1) - Inserir valor inicial (2) - Somar (3) - Subtrair (4) - Multiplicar (5) - Dividir (6) - Potencia (7) - Inverter Sinal (8) - Limpar Resultado
You should implement 2 classes:
1) Main, contains the part of interaction with the user (interface and data entry),
2) Calculator, contains the implementation of the methods responsible for the calculation itself (add, divide, multiply, etc.).
Main Class:
import java.util.Scanner;
public class Principal {
public static void main(String[] args) {
// menu
System.out.println("CALCULADORA \n");
System.out.println("Resultado: \n");
System.out.println("Menu:");
System.out.println(" (1) - Inserir valor inicial;");
System.out.println(" (2) - Somar;");
System.out.println(" (3) - Subtrair;");
System.out.println(" (4) - Multiplicar;");
System.out.println(" (5) - Dividir;");
System.out.println(" (6) - Potencia;");
System.out.println(" (7) - Inverter Sinal;");
System.out.println(" (8) - Limpar Resultado;");
//Principal p = new Principal();
//p.limparTela();
}
public void limparTela() {
for (int i=0; i< 100; i++) {
System.out.println("\n");
}
}
}
Calculator class
public class Calculadora {
// Atributos
private Double resultado = 0.0;
// Metodos
public void inserirValorInicial(Double valor) { }
public Double obterResultado() { return 0.0; }
public void somar(Double valor) { }
public void subtrair(Double valor) { }
public void multiplicar(Double valor) { }
public void dividir(Double valor) { }
public void inverterSinal() { }
public void potencia(int potencia) { }
public void limpar() { }
}