Rock-Paper-Scissors Game

The Rock-Paper-Scissors Game is a fun, interactive command-line game built in Java to demonstrate the use of conditional logic, user input handling, and random number generation. The player competes against the computer by choosing Rock, Paper, or Scissors. The computer’s choice is generated using the Random class. The winner is decided based on standard rules, and the game keeps track of the number of wins, losses, and ties. This project is beginner-friendly and encourages logical thinking, control flow usage, and real-time input processing. It can optionally be extended into a GUI version using Swing, making it an ideal stepping stone toward graphical Java applications.

The Rock-Paper-Scissors Game is a simple yet engaging command-line application developed in Java. It allows a user to play the classic game against the computer, using conditional logic and random number generation. This project is ideal for beginners and helps in reinforcing foundational programming concepts such as user input handling, decision-making structures, and working with randomness.

📌 Key Features:

  • User Input: Players can choose between Rock, Paper, or Scissors through a numeric or text-based menu.

  • Computer Choice: The computer randomly selects an option using Java’s Random class.

  • Game Logic: The winner is determined based on the traditional rules:

    • Rock beats Scissors

    • Scissors beats Paper

    • Paper beats Rock

  • Score Tracking: The application keeps count of total wins, losses, and ties during the session.

  • Replay Option: Allows users to play multiple rounds and exit the game when desired.

🔧 Technologies & Concepts Used:

  • Random Class: Generates the computer’s move randomly each round.

  • If-Else & Switch Statements: Implements core game logic to determine results.

  • Scanner Class: Captures user input via the console.

  • Variables and Counters: Tracks the number of wins, losses, and draws.

  • Looping Structures: Uses do-while or while loops to allow repeated gameplay.

🎯 Learning Outcomes:

This project helps learners:

  • Understand and apply conditional statements for logic-based decisions.

  • Work with random values to simulate unpredictability.

  • Practice handling real-time user input in the console.

  • Build an interactive and dynamic game flow using Java basics.

  • Learn to use counters and variables effectively for score tracking.

🔄 Future Scope:

The game can be enhanced in many ways:

  • Adding a Graphical User Interface (GUI) using Java Swing or JavaFX.

  • Introducing difficulty levels, timer-based gameplay, or sound effects.

  • Implementing a leaderboard or saving high scores using files.

  • Adding multiplayer support or online gameplay functionality.

✅ Conclusion:

The Rock-Paper-Scissors Game in Java is an excellent introductory project that combines fun with learning. It allows developers to explore core programming concepts while creating a user-friendly and interactive experience. This game project not only strengthens logical thinking but also demonstrates how even simple games can be brought to life through code.

RockPaperScissors.java

import java.util.Random;
import java.util.Scanner;

public class RockPaperScissors {
    private static int userWins = 0;
    private static int computerWins = 0;
    private static int ties = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Random rand = new Random();

        String[] choices = {“rock”, “paper”, “scissors”};

        System.out.println(“🎮 Welcome to Rock-Paper-Scissors Game!”);
        int choice;

        do {
            System.out.println(“\nChoose your option:”);
            System.out.println(“1. Rock”);
            System.out.println(“2. Paper”);
            System.out.println(“3. Scissors”);
            System.out.println(“0. Exit”);
            System.out.print(“Enter your choice: “);
            choice = sc.nextInt();

            if (choice >= 1 && choice <= 3) {
                String userChoice = choices[choice – 1];
                String compChoice = choices[rand.nextInt(3)];

                System.out.println(“🧑 You chose: ” + userChoice);
                System.out.println(“🤖 Computer chose: ” + compChoice);

                String result = getResult(userChoice, compChoice);
                System.out.println(“🎯 Result: ” + result);
            } else if (choice != 0) {
                System.out.println(“❌ Invalid choice. Try again.”);
            }
        } while (choice != 0);

        System.out.println(“\n📊 Final Score:”);
        System.out.println(“✅ You won: ” + userWins);
        System.out.println(“❌ Computer won: ” + computerWins);
        System.out.println(“🤝 Ties: ” + ties);
        System.out.println(“👋 Thanks for playing!”);
    }

    private static String getResult(String user, String comp) {
        if (user.equals(comp)) {
            ties++;
            return “It’s a Tie!”;
        }

        if ((user.equals(“rock”) && comp.equals(“scissors”)) ||
            (user.equals(“scissors”) && comp.equals(“paper”)) ||
            (user.equals(“paper”) && comp.equals(“rock”))) {
            userWins++;
            return “You Win!”;
        } else {
            computerWins++;
            return “Computer Wins!”;
        }
    }
}
Scroll to Top