Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Lock {
- int firstNum;
- int secondNum;
- int thirdNum;
- public void init(){
- firstNum = (int)(Math.random()*10);
- secondNum = (int)(Math.random()*10);
- thirdNum = (int)(Math.random()*10);
- }
- public int first(){
- return firstNum;
- }
- public int second(){
- return secondNum;
- }
- public int third(){
- return thirdNum;
- }
- public void open(){
- System.out.println("Lock Opened!");
- }
- }
- public class Main {
- public static void main(String []args){
- int numOne;
- int numTwo;
- int numThree;
- int tries = 3;
- boolean open = false;
- //setup lock
- Lock lock = new Lock();
- lock.init();
- Scanner input = new Scanner(System.in);
- do{
- System.out.println("Enter three numbers between 1 and 10.");
- numOne = input.nextInt();
- numTwo = input.nextInt();
- numThree = input.nextInt();
- System.out.println("Checking..");
- //checks users numbers against lock numbers
- if(numOne == lock.first()){
- if(numTwo == lock.second()){
- if(numThree == lock.third()){
- open = true;
- lock.open();
- }
- }
- }else {
- System.out.println("Sorry Wrong Numbers");
- --tries;
- System.out.println("You have tries " + tries + " left. \n");
- if(tries == 0){
- System.out.println("Sorry you've been locked out.");
- System.out.println("The correct combo was: " + lock.first() + lock.second() + lock.third());
- break;
- }
- }
- }while(!open);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement