Advertisement
grodek118

EPS Game (Guess Color Game)

Dec 1st, 2022 (edited)
898
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.  
  6.     public static void main(String[] args){
  7.  
  8.         int randomNumber;
  9.  
  10.         Scanner scanner = new Scanner(System.in);
  11.         Random random = new Random();
  12.         String color;
  13.         String guessedColor;
  14.         int sum = 0;
  15.         randomNumber = random.nextInt(5);
  16.  
  17.         switch (randomNumber)
  18.         {
  19.             case 0:
  20.                 color = "Red";
  21.                 break;
  22.  
  23.             case 1:
  24.                 color = "Green";
  25.                 break;
  26.  
  27.             case 2:
  28.                 color = "Blue";
  29.                 break;
  30.  
  31.             case 3:
  32.                 color = "Orange";
  33.                 break;
  34.  
  35.             case 4:
  36.                 color = "Yellow";
  37.                 break;
  38.  
  39.             default:
  40.                 color = "rzulty";
  41.                 break;
  42.         }
  43.  
  44.         System.out.println(color);
  45.  
  46.         System.out.println("Guess the color");
  47.  
  48.         for (int i = 0; i < 10; i++)
  49.         {
  50.             guessedColor = scanner.nextLine();
  51.  
  52.             if (guessedColor.equalsIgnoreCase(color))
  53.             {
  54.                 sum++;
  55.             }
  56.         }
  57.         System.out.println("You guessed it " + sum + " times");
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement