I am making a CLI calculator and I am trying to add a clear button but cannot figure out how to clear all the user input and start the display from the beginning. I tried using the reset method and that didn't seem to do the trick.
System.out.println("Enter any of the following:");
System.out.println(" 1 2 3 4 5 6 7 8 9 ");
System.out.println(" + - * / = ");
System.out.println("Enter AC to reset ");
double firstNum = input.nextDouble();
input.nextLine();
if (input.equals(clear)) {
input.reset();
}
System.out.println("Display 1: " + firstNum);
System.out.println("Display 2: " + firstNum);
System.out.println("Operator: ");
String operand = input.nextLine();
System.out.println("Display 1: " + firstNum + " " + operand);
System.out.println("Display 2: " + firstNum );
if (operand.equals("=")) {
break;
}
System.out.println("Enter your next number: ");
double secondNum = input.nextDouble();
input.nextLine();
calculate(firstNum, operand, secondNum);
System.out.println("Display 1: " + firstNum + " " + operand + " " + secondNum );
firstNum = answer;
System.out.println("Display 2: " + answer);
}
System.out.println("Answer: " + answer);
}