import java.util.Scanner; public class Chapter8{ // user need to find the combo to open the lock // the right combo is first right, left and then right Scanner userInput = new Scanner(System.in); public void printMenu() { System.out.println("1) Choose combo"); System.out.println("2) Reset"); System.out.println("3) Try to open the lock "); System.out.println("4) Finish"); } public void combo() { System.out.println("Type in the right code to open the lock: "); String inputOne = userInput.next(); String inputTwo = userInput.next(); String inputThree = userInput.next(); return; } public void reset() { userInput.reset(); System.out.println("You have reset!"); } public void open() { String inputOne = userInput.next(); String inputTwo = userInput.next(); String inputThree = userInput.next(); if (inputOne.equals("right") && inputTwo.equals("left") && inputThree.equals("right")) // the code ignores this { System.out.println("You succed to open the lock"); } else { System.out.println("You got wrong combo"); // this line shows in the console even though the user input in the console is right } } }
Main
import java.util.Scanner; public class Main { public static void main(String[] args) { Chapter8 Chapter8 = new Chapter8(); boolean running = true; do { Chapter8.printMenu(); int choice = Chapter8.userInput.nextInt(); switch(choice) { case 1: Chapter8.combo(); break; case 2: Chapter8.reset(); break; case 3: Chapter8.open(); break; } } while(true); } }