Advertisement
HansYeboah

Guessing game pro

Jan 22nd, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.50 KB | None | 0 0
  1. package studies;
  2. import java.util.Scanner;
  3. import java.util.Random;
  4.        
  5. public class Studies {
  6.  
  7.     public static void main(String[] args) {
  8.         Random randomNumber = new Random();
  9.         //
  10.         int a;
  11.         int b;
  12.         int c;
  13.         int d;
  14.         int e;
  15.        
  16.         int attempts = 10;
  17.        
  18.         Scanner input = new Scanner(System.in);
  19.         System.out.println("Guess five(5) numbers from 1 - 20: ");
  20.         //Creating a loop for the game
  21.         for(int counter =1; counter <= 100; counter++){
  22.        
  23.             /*User's numbers are placed*/
  24.             int numA = input.nextInt();
  25.             int numB = input.nextInt();
  26.             int numC = input.nextInt();
  27.             int numD = input.nextInt();
  28.             int numE = input.nextInt();
  29.             /*this will show the right number and the number you input*/
  30.             a = 1+randomNumber.nextInt(20);
  31.             System.out.println("right number: "+a+"  Your answer: "+ numA);
  32.             b = 1+randomNumber.nextInt(20);
  33.             System.out.println("right number: "+b+"  Your answer: "+ numB);
  34.             c = 1+randomNumber.nextInt(20);
  35.             System.out.println("right number: "+c+"  Your answer: "+ numC);
  36.             d = 1+randomNumber.nextInt(20);
  37.             System.out.println("right number: "+d+"  Your answer: "+ numD);
  38.             e = 1+randomNumber.nextInt(20);
  39.             System.out.println("right number: "+e+"  Your answer: "+ numE);
  40.            
  41.             //the logic part of the program
  42.             if(a == numA && b == numB && c == numC && d == numD && e == numE ){
  43.                 System.out.println("Excellent!!!");
  44.                
  45.             }else if((a==numA && b==numB) || (a==numA && c==numC) || (a==numA &&d==numD) || (a==numA &&e==numE) || (b==numB &&c== numE) || (b==numB &&d==numD) || (b==numB &&e==numE) || (c==numC &&d==numD )|| (d==numD && e==numE)){
  46.             System.out.println("Good!!!");
  47.            
  48.             /*Game closes here if game is won*/
  49.             System.exit(0);
  50.             }else{
  51.                 System.out.println("You lose!!!");
  52.                 System.out.println("\n\nTry Again...");
  53.            
  54.                 attempts--;/*this will reduce if player keeps losing*/
  55.             System.out.println("Attempts remaining: "+attempts);
  56.             //loop repeats
  57.             }
  58.            
  59.                        
  60.                    
  61.         }
  62.        
  63.        
  64.        
  65.            
  66.         }
  67.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement