0% found this document useful (0 votes)
22 views

code for a game of rock paper and scissors

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

code for a game of rock paper and scissors

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Session: 2024-25

MINI PROJECT REPORT


On

“Rock Paper Scissor”

BACHELOR OF TECHNOLOGY IN COMPUTER


SCIENCE AND ENGINEERING

Submitted to- Mrs. Sonam Jahan


(Department of Computer Science & Engineering )

Submitted by-
Student name: Shankar--(2300680100266)
Saurabh Giri--(2300680100263)

3RD SEMESTER
DEPARTMENT OF
COMPUTER SCIENCE AND ENGINEERING
MEERUT INSTITUTE OF ENGINEERING AND TECHNOLOGY, MEERUT
DECLARATION

We hereby declare that the project entitled which is being submitted as Mini Project in department
of Computer Science and engineering to Meerut Institute of Engineering and Technology, Meerut
(U.P.) is an authentic record of our genuine work done under the guidance of “Mr. Shivam”
Computer Science and Engineering, Meerut Institute of Engineering and Technology, Meerut.

Date: 19/12/2024 Name of student: Shankar(2300680100266)

Saurabh Giri--(2300680100263)
CERTIFICATE

This is to certify that mini project report entitled – “ROCK PAPER SCISSOR” submitted by
Shankar anand Saurabh ri has been carried out under the guidance of “Mr. Shivam” Computer
Science and Engineering, Meerut Institute of Engineering and Technology, Meerut. This project
report is approved for Mini Project (KCN 354) in 3rd semester in “CSE” from Meerut Institute of
Engineering and Technology, Meerut.

Internal Examiner :
ACKNOWLEDGEMENT

I express my sincere indebtedness towards our guide of Computer Science and Engineering,
Meerut Institute of Engineering and Technology, Meerut for his valuable suggestion, guidance and
supervision throughout the work. Without his king patronage and guidance the project would not
have taken shape. I would also like to express my gratitude and sincere regards for his kind
approval of the project. Time to time counseling and advises.

I would also like to thank to our HoD Department of Computer Science and engineering, Meerut
Institute of Engineering and Technology, Meerut for his expert advice and counseling from time
to time.

I owe sincere thanks to all the faculty members in the department of Computer Science and
engineering for their kind guidance and encouragement time to time.
Table of contents

Description page no.

Declaration 2

Certificate 3

Acknowledgement 4

Chapter 1 Introduction

Chapter 2 Technologies used

Chapter 3 System Design

Chapter 4 Implementation

Appendices Implementation code

Chapter 5 Testing

Chapter 6 Result

Chapter 7 Conclusion

Chapter 8 Future Enhancement

Chapter 9 References
INTRODUCTION

1.1 Objective

Create an interactive console-based game where the user plays Rock, Paper, Scissors against the
computer.

1.2 Purpose

The program starts by displaying a welcome message and instructions for the user to choose
one of the three options:

1 for Rock

2 for Paper

3 for Scissors

1.3 Scope

• The scope of the game in Java can refer to the range of its features, as well as the visibility
of variables and methods within the program. In a basic Rock, Paper, Scissors game, the
scope will be simple, focusing on gameplay logic, user input, and determining the winner,
but it can be expanded to include more features or a more advanced architecture depending
on the requirements.
TECHNOLOGIES USED
1. Java Programming Language

• The core technology for implementing the game logic, user interaction, and overall
structure of the application.

2. Standard Java Libraries (JDK)

• java.util.Scanner: For reading user input from the console.

• java.util.Random: To randomly select the computer's choice (rock, paper, or scissors).

• java.lang.String: For handling string operations (e.g., comparing user input and the
computer's choice).

3. Control Structures

• Conditionals (if, else, switch): To evaluate the game's rules and determine the winner.

• Loops (for, while): For repeating the game or providing a loop for multiple rounds if
needed.

4. Object-Oriented Programming (OOP) Concepts (Optional)

• Classes and Objects: You can structure the game using classes (e.g., a Game class for
managing the game and Player classes for human/computer players).

• Methods: Break down the game logic into smaller methods for easier management and
readability.

5. Exception Handling

• Use try-catch blocks to handle invalid user input or other potential errors.

6. Graphical User Interface (GUI) - (Optional)

• If you want to enhance the user experience beyond the console, you can use:

o Swing: A GUI toolkit that allows you to create windows, buttons, and other
components.

o JavaFX: Another option for building modern GUIs with a richer set of controls and
better visual effects.
7. File Handling (Optional)

• If you want to save scores, game history, or preferences, you can use Java’s file-handling
classes (e.g., File, FileWriter, BufferedReader) to store data to text files.

HARDWARE REQUIREMENTS:

Any modern computer (Windows, macOS, or Linux) with at least 4GB of RAM

Processor: Intel i3 or equivalent AMD

Storage: 1GB of free disk space (minimum)

SOFTWARE REQUIREMENTS: Java Development Kit (JDK)


Command-Line Tools (for Compilation and Running)
Optional - GUI Libraries (for GUI-Based Applications)
: : Scripting language : HTML Java Script
IMPLEMENTATION

import java.util.Random;

import java.util.Scanner;

public class RockPaperScissors {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

Random random = new Random();

String[] choices = {"Rock", "Paper", "Scissors"};

int userChoice, computerChoice;

// Game loop

while (true) {

System.out.println("Enter 0 for Rock, 1 for Paper, 2 for Scissors, or 3 to quit.");

userChoice = scanner.nextInt();

// Exit condition

if (userChoice == 3) {

System.out.println("Thanks for playing!");


break;

// Check for valid input

if (userChoice < 0 || userChoice > 2) {

System.out.println("Invalid choice. Please try again.");

continue;

// Computer randomly picks a choice

computerChoice = random.nextInt(3);

// Display choices

System.out.println("You chose: " + choices[userChoice]);

System.out.println("Computer chose: " + choices[computerChoice]);

// Determine the winner

if (userChoice == computerChoice) {

System.out.println("It's a tie!");

} else if ((userChoice == 0 && computerChoice == 2) ||

(userChoice == 1 && computerChoice == 0) ||

(userChoice == 2 && computerChoice == 1)) {

System.out.println("You win!");
} else {

System.out.println("Computer wins!");

scanner.close();

}
5. Testing
Write the program step by step:
Display instructions.Take user input.
Generate and display the computer's choice.
Implement game logic to determine the winner.
Display the result.Use helper methods (choiceToString and
determineWinner) to simplify the main program.
Test the Program:
Test Cases:
Valid inputs: Ensure the program works correctly for Rock, Paper, and
Scissors.
Invalid inputs: Verify the program handles invalid inputs gracefully.
Edge cases: Test for repeated draws and other scenarios (e.g., user always
choosing the same option).
Ensure outputs are user-friendly and accurate.
6. Results

User Interaction:

The program starts by displaying a welcome message and instructions for the user to choose one
of the three options:

1 for Rock

2 for Paper

3 for Scissors

Input Handling:

The user enters their choice as an integer.

The input is validated to ensure it is within the valid range (1 to 3).

If the input is invalid, the program terminates with an appropriate message.

Computer's Choice:

The computer generates a random choice (1, 2, or 3) using the Random class.

Choice Display:

The program converts both the user's and the computer's numeric choices into their corresponding
string representations ("Rock", "Paper", or "Scissors") for display.
Winner Determination:

The program compares the user's and the computer's choices to determine the outcome:

A draw if both choices are the same.

The computer wins if its choice beats the user's.

Otherwise, the user wins.

Output:

The program outputs both choices and declares the result (win, lose, or draw).

Logic Flow

User Input:

Prompt the user to choose Rock, Paper, or Scissors.


7.Conclusion
The Rock-Paper-Scissors game implemented in Java provides a simple yet effective
demonstration of fundamental programming concepts, including user input handling, random
number generation, control structures, and basic game logic. Throughout the development of this
project, several key learning outcomes and technical skills were achieved
8.Future Enhancements

• Adding support for private chats between users.

• Integrating multimedia sharing (images, videos).

• User authentication and login systems.

• Deploying the application on a cloud server for global access.

9.References

Java Tutorials - https://docs.oracle.com/javase/tutorial/

Stack Overflow - https://stackoverflow.com/questions/tagged/java

You might also like