Check if the user wants to quit break operatorChar

Check if the user wants to quit break operatorchar

This preview shows page 2 out of 2 pages.

quitbreak;}operatorChar = input.charAt(input.length() - 1); // Determine the operatorbeing choseninputNum = Integer.parseInt(input.substring(0, input.length() - 1)); // Determines the number// being chosen by userif (GameOperator.getFromChar(operatorChar) == null || !list.contains(inputNum)) {// Makes sure the input is in a valid formatSystem.out.println("WARNING: Invalid input");continue; // Returns to beginning of the while loop if input is invalid}list.addNode(new GameNode(rndm)); // Adds a new node to the end of the listlist.applyOperatorToNumber(inputNum, GameOperator.getFromChar(operatorChar));moves++; // Counts the operation as a valid moves and increments counterif (list.contains(targetNum)) { // Checks if the target number has been reachedgameOver = true; // Sets boolean to true in order to leave while loopSystem.out.println("Congratulations you won in " + moves + " moves!");System.out.println("Final: " + list.toString());}}scnr.close();}}
Background image

You've reached the end of your free preview.

Want to read both pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture