code for a game of rock paper and scissors
code for a game of rock paper and scissors
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.
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
Declaration 2
Certificate 3
Acknowledgement 4
Chapter 1 Introduction
Chapter 4 Implementation
Chapter 5 Testing
Chapter 6 Result
Chapter 7 Conclusion
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.
• 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.
• 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.
• 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
import java.util.Random;
import java.util.Scanner;
// Game loop
while (true) {
userChoice = scanner.nextInt();
// Exit condition
if (userChoice == 3) {
continue;
computerChoice = random.nextInt(3);
// Display choices
if (userChoice == computerChoice) {
System.out.println("It's a tie!");
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:
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:
Output:
The program outputs both choices and declares the result (win, lose, or draw).
Logic Flow
User Input:
9.References