So I'm just starting out with JAVA at school and within the first week I'm way beyond what my book can do for me so I started writing a calculator that had four inputs, three for numbers and the fourth one for what I wanted to do to the numbers i.e. addition subtraction multiplication, and limited division(no decimals ).
public class Calculator { public int number1; public int number2; public int number3; public int total; public String function; public void Number3(int number3) { number3 = number3; } public int Calculatorinput(int number1, int number2,String function) { if(number3 == null) {number3 = 0;} else{number3 = number3;} if (function == "+") {total = number1+number2+number3;} else if (function == "-") {total = number1-number2-number3;} else if (function == "x") {total = number1*number2*number3;} else if (function =="/") {total = number1/number2/number3;} if (total == 0) {System.out.println("something is wrong");} else {total = total;} return total; } }
I know at this point it won't compile, the problem I'm having is making that third number an optional integer within the calculator, I know I'm either really close....or waaay off.