NPS INTERNATIONAL, CHENNAI
Perumbakkam, Chennai – 600 100
ROLL NO: 18
CERTIFICATE
Certified that this is a bonafide record of project
work done by Neeraj
Prasanna
………………………………………….in the subject
Computer Science during the academic year
2021 to 2022.
Date: 23.11.2021 Teacher-in-Charge
Submitted to the Practical Examination in NPS
International,
Chennai held on ………………………..
Principal Examiner
Index
S. Contents Page
No. No.
1 Acknowledgement 1
2 Synopsis 2
3 Java Programming Language 3
4 Features Used 5
5 Packages Used 7
6 Algorithm 7
7 Program 15
8 Screenshot 28
9 Output 29
10 Bibliography 40
ACKNOWLEDGEMENT
This project would have not been possible without the
guidance and the help of several individuals who contributed
and extended their valuable assistance in the preparation
and completion of this study.
Firstly, I express utmost gratitude to my principal Mrs. Sudha
Balan for her selfless interest in my project. I thank our
computer teacher, Mrs. Jeba Andrew whose inputs and
encouragement has been key in the completion of this
project work.
I thank all the members of my family who always had a kind
consideration regarding all my project. Last but not the least,
I thank all my classmates for all the cooperation and
resources they extended to me.
SYNOPSIS
OBJECTIVE:
The objective of my program is to simulate an arcade on a
smaller scale, and create an interactive experience between
the user and the computer
INTRODUCTION:
Arcades are a popular form of entertainment. They are found
in most shopping malls these days. On playing on an arcade
machine, one wins points which they can cash in for various
prizes,
WHY DID I DO THIS PROGRAM?
There are two main reasons for the above question.
I’ve visited numerous arcade centers across various
shopping malls, and I enjoy playing on most of them. When I
was younger, I enjoyed playing on them to win the prizes,
but as I grew older, I began to ponder the question, “How do
Arcade games work?”. This inspired me to develop a
program that simulates an Arcade on a smaller scale.
The next reason is that I grew up playing games like Rock,
Paper, Scissors! with my friends and family. While growing
up, I always thought it would be cool to play one of my
favorite childhood games against a computer, which had a
mind of its own.
Hence I decided to develop this project.
JAVA PROGRAMMING LANGUAGE
Java is a programming language (Technology). It was first
developed by James Gosling at Sun Microsystems, which is
now a part of Oracle Corporation. It was released in 1995 as
a part of Sun Microsystems' Java platform. The language has
developed much of its syntax from C and C++. Java can run
on many different operating systems. This makes Java
platform independent. Java does this by making the Java
compiler turn code into Java byte code instead of machine
code. This means that when the program is executed, the
Java Virtual Machine interprets the byte code and translates
it into machine code.
WHY DID I USE JAVA?
JAVA is a very user-friendly programming language
whose functions and operations are very easy to learn
and use.
JAVA is an object-oriented programming which makes
the whole program modular, flexible and extensible.
JAVA is platform independent, meaning that the user can
run my program in whatever system that he prefers.
He/she is not restricted to one particular operating
system.
Using JAVA, I could use several operations and features
(such as arrays) in a modular and systematic manner.
Also, JAVA has a command called Math.random(), which
allowed me to give the computer a “Mind”. This means
that by using Math.random(), the computer could
generate random values and I could use those values to
automate responses from the computer.
HARDWARE REQUIREMENTS
Minimum:
64Mb main memory,
Pentium II processor or equivalent
Recommended:
128Mb main memory,
400MHz Pentium III processor or above
Software requirements
J2SE 1.4.2 (Java 2 SDK version 1.4.2) or newer must be
installed.
BlueJ versions up to version 1.3.0 also run on JDK 1.3.x.
BlueJ versions up to version 1.1.3 also run on JDK 1.2.2.
FEATURES USED
Switch case:
switch(user_choice) //checking the user's input to see if it
matches the following cases
case 'r': //if user entered rock
{
……
break;}
case 'p': //if user entered paper
……
break;}
case 's': //if user entered scissors
……
break;}
default:
System.out.println("Invalid input.\n"); //if user
entered an invalid value
Thread.sleep(long):
try{
Thread.sleep(1000);
System.out.println("Rock"); }
catch(Exception e){
System.err.println("ERROR");}
For – loop:
for(Round_Control=0;Round_Control<NumberOfRounds;Round
_Control++) //loop to control the number of rounds
{ System.out.println("******************************************
**************************");
for(Game_Control=0;Game_Control<GamesPerRound;Game_C
ontrol++) //loop to control the number of games per round
{ ……
…. }
If-else condition
if(LeaderBoardScore>=5000){
System.out.println("----------------- LEADERBOARD
----------------- ");
System.out.println("
"+Username+"---"+LeaderBoardScore);
System.out.println(" Neeraj --- 5000 ");}
else{System.out.println("-----------------
LEADERBOARD ----------------- ");
System.out.println(" Neeraj --- 5000 ");
System.out.println("
"+Username+"---"+LeaderBoardScore);}
PACKAGES USED
For my project I used the java.util package in order to
utilize its input and time delay features. I used the
“util” package as my program comprises mainly of
user’s input, hence making the package very
necessary. I also needed to delay the code at certain
points in time, so I needed to use the
Thread.sleep(long) command, which also comes as a
part of the java.util package I preferred the util
package over the “io” (input/output package) as I felt
that the former made the whole program simple and
well organized.
ALGORITHM
Step 1 : START
Step 2 : Create objects of other classes inside the main class.
Step 3 : Display welcome message and inform user to type - help if
they don’t know the commands
Step 4 : If the user types in -help, call the DisplayCommands()
method of the HelpCommands class by using the object
hlp
hlp.DisplayCommands();
Step 5 : If the user types in another command, perform subsequent
steps
Step 5 ‘a’: If the user types in -rps, initiate the Rock, Paper,
Scissors! Game
Step 5 ‘a’ 1: Start
Step 5 ‘a’ 2: Accept the number of rounds and number of
games per round as input from the user
Step 5 ‘a’ 3 :The computer’s choice is decided by obtaining a
random value via Math.random() function,
then multiplying the random value by 2 and
then adding 1, and finally storing the value in
variable computer_choice, i.e.
computer_choice=(int)Math.round
(Math.random()*2+1);
Step 5 ‘a’ 4 : For each iteration of the inner for loop, a message
will be printed in the format
Computer has chosen.
Enter your choice
//(wait 1 sec)using Thread.sleep(1000)
Rock
//(wait 1 sec)using Thread.sleep(1000)
Paper
//(wait 1 sec)using Thread.sleep(1000)
Scissors!
Step 5 ‘a’ 5 : The user inputs their choice either as ‘r’ or ‘R’, ‘p’
or ‘P’ or ‘s’ or ‘S’ for rock, paper and scissors
respectively
Step 5 ‘a’ 6 : Now, the checking begins
If the user has inputted ‘r’ i.e. rock,
and the computer has chosen 1 i.e.
rock, then it is a tie. The same is
printed:
Computer chose -> Rock
You chose ------> Rock
Result = TIE <
If the user has inputted ‘r’ i.e. rock,
and the computer has chosen 2 i.e.
paper, then the computer wins. The
same is printed:
Computer chose -> Paper
You chose ------> Rock
Result = Computer WINS <
If the user has inputted ‘r’ i.e. rock,
and the computer has chosen 3 i.e.
scissors, then the user wins. The
same is printed:
Computer chose -> Rock
You chose ------> Rock
Result = User WINS <
If the user has inputted ‘p’ i.e. paper,
and the computer has chosen 1 i.e.
rock, then the user wins. The same is
printed:
Computer chose -> Rock
You chose ------> Paper
Result = User WINS <
If the user has inputted ‘p’ i.e. rock,
and the computer has chosen 2 i.e.
paper, then it is a tie. The same is
printed:
Computer chose -> Paper
You chose ------> Paper
Result = TIE <
If the user has inputted ‘p’ i.e. paper,
and the computer has chosen 3 i.e.
scissors, then the computer wins. The
same is printed:
Computer chose -> Scissors
You chose ------> Paper
Result = Computer WINS
If the user has inputted ‘s’ i.e.
scissors, and the computer has
chosen 1 i.e. rock, then the computer
wins. The same is printed:
Computer chose -> Rock
You chose ------> Scissors
Result = Computer WINS <
If the user has inputted ‘s’ i.e.
scissors, and the computer has
chosen 2 i.e. paper, then the user
wins. The same is printed:
Computer chose -> Paper
You chose ------> Scissors
Result = User WINS <
If the user has inputted ‘s’ i.e.
scissors, and the computer has
chosen 3 i.e. scissors, then it is a tie.
The same is printed:
Computer chose -> Scissors
You chose ------> Scissors
Result = TIE <
If the user wins a game, the
user_Score variable increments by 1
(originally 0) and if the computer wins
a game, the comp_score variable
increments by 1 (originally 0)
Step 5 ‘a’ 7 : The final scores of the user and computer are
calculated by multiplying the user_score and
comp_score variables by 100, respectively.
Step 5 ‘a’ 8 :If the user’s score is greater than the computer
score, then the User has won. The same is
printed
Congratulations! You’ve won against the
computer!
If the user’s score is equal to the computer’s
score, then it is a tie. The same is printed.
It is a TIE
If the user’s score is lesser than the computer’s
score, then the computer has won. The same is
printed
The Computer has won against you.
Step 5 ‘a’ 9 :The value of user_score is returned to the calling
method
Step 5 ‘b’ : If the user enters -gtn, initiate the Guess The
Number! Game
Step 5 ‘b’ 1 : Print the introduction message
Step 5 ‘b’ 2 : Use Math.random() to obtain the random number,
multiply it by 100 and store it in variable
RandomNumber. Then explicitly convert
RandomNumber to int data type and store the
value in RandomNumber_int;
Step 5 ‘b’ 3 : Begin the for loop, such that the
loop keeps executing unless the number that
the user enters is equal to the random number
chosen by the computer
Step 5 ‘b’ 4 : If the number entered by the user is equal to the
random number chosen by the computer, then
print the following message:
“Congratulations! You guessed the right number. It
was ____” (the random number)
“You took 1 try in order to guess it”
(if the number of tries taken is 1)
OR
“You took ___ tries in order to guess it “(if the number
of tries is more than 1)
The loop is exited after performing this command
Step 5 ‘b’ 5 : If the number entered by the user is greater than
the random number chosen by the computer,
then print the following message:
“The number you’ve chosen is higher than the random
number generated”
Step 5 ‘b’ 6 : If the number entered by the user is lower than
the random number chosen by the computer,
then print the following message:
“The number you’ve chosen is lower than the random
number generated”
Step 5 ‘b’ 7 : Print the final score of the User
Step 5 ‘b’ 8 : return the value of User_Score to the calling
function
Step 5 ‘c’ : If the user enters -crdts, call the DisplayCredits()
method of the Credits class by using the object
cr
cr.DisplayCredits();
Step 5 ‘d’ : If the user enters -ldrbrd, then initiate leaderboard
mode
Step 5 ‘d’ 1 : Accept the username of the user
Step 5 ‘d’ 2 : Print introduction message
Step 5 ‘d’ 3 : call RockPaperScissors class followed by
GuessTheNumber Class. On calling the classes,
the final scores will be added together and
stored into variable LeaderBoardScore.
Step 5 ‘d’ 4 : Compare the value of LeaderBoardScore with 5000
(My (Neeraj’s) highest score in the game), and
print the leaderboard accordingly
Step 5 ‘e’ : If the user enters -rulesRPS or -rulesGTN, then invoke the
methods RPSrules() and GTNrules from the
Rules class, respectively, by using the object
rls.
rls.RPSrules(); (For displaying the rules of the game Rock,
Paper, Scissors!)
OR
rls.GTNrules(); (For displaying the rules of the game
Guess The Number!)
Step 5 ‘f’ : If the user enters the command -exit, then display the
credits of the game, by calling the DisplayCredits()
method of the Credits class by using the object cr
cr.DisplayCredits();
And then display the thank you message
Step 5 ‘g’ : If the user enters a command that doesn’t exist in the
game, then print the following message:
“ ¯\_(ツ)_/¯ Hmmmmmm, I don't think such a command exists
in this game. Please check your spelling and try again”
Step 6 : END
PROGRAM
Class ARCADE:
import java.util.*; //importing utility package
public class ARCADE
public String Username="";
public int choice=0;
public String input=""; //class variables declaration
public void main(){
RockPaperScissors rps = new RockPaperScissors();
GuessTheNumber gtn = new GuessTheNumber();
HelpCommands hlp = new HelpCommands();
LeaderBoard lb = new LeaderBoard();
Credits cr = new Credits () ;
Rules rls = new Rules(); //creating objects of other classes in order to access member methods
Scanner sc=new Scanner(System.in); //creating object sc of Scanner class in order to accept
input from the user
System.out.println("1-0-101-/1-0-101-/1-0-101-/1-0--|1-0-101-/1-0-101-/1-0-101-/1-0--|");
System.out.println("1-0-101-/1-0-101-/1-0-101-/1-0--|1-0-101-/1-0-101-/1-0-101-/1-0--|");
System.out.println("----------------- Neeraj's Arcade --------------");
System.out.println("---Designed and Developed by Neeraj Prasanna---");
System.out.println("\"Hello, and welcome to Neeraj's Arcade. Designed and \ndeveloped with
the BlueJ JDK environment, I've tried to create an interactive experience between the
user and the computer. \nI hope the user reading this enjoys playing the games I've
made.");
System.out.println("Alright, that's all I have to say. Good luck, and have fun\" - Neeraj :-)");
System.out.println(" There are two minigames available for play in this arcade. They are \n\t
Rock, Paper, Scissors!\n\t and \n\t Guess the Number! ");
System.out.println("Type -help in order to view the list of commands for moving around this
program ");
for( ; input!="-exit" ; ){
input=sc.next().trim();
if(input.equalsIgnoreCase("-help")) //if inputted command is "-help"{
System.out.println("--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/
--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/");
hlp.DisplayCommands();
System.out.println(" Once you've understood how the commands work, you can
try them out! ");}
else if(input.equalsIgnoreCase("-rps")) //if inputted command is "- rps" {
System.out.println("--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/
--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/");
rps.RPS();}
else if(input.equalsIgnoreCase("-gtn")) //if inputted command is "-gtn"
{gtn.GTN();}
else if(input.equalsIgnoreCase("-crdts")) //if inputted command is "- crdts"
System.out.println("--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/
--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/");
cr.DisplayCredits();}
else if(input.equalsIgnoreCase("-ldrbrd")) //if inputted command is "-ldrbrd" {
System.out.println("--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/
--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/");
System.out.print("Before entering Leaderboard mode, please enter a username : ");
Username=lb.inputUserName(); //accepting username and storing it in a variable in the
LeaderBoard class
System.out.println();
lb.LeaderBoardMode();}
else if(input.equalsIgnoreCase("-rulesRPS")) //if inputted command is "-rulesRPS"{
System.out.println("--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/
--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/");
rls.RPSrules();
else if(input.equalsIgnoreCase("-rulesGTN")) //if inputted command is "-rulesGTN"
System.out.println("--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/
--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/");
rls.GTNrules();
else if(input.equalsIgnoreCase("-exit")) //if inputted command is "-exit"
System.out.println("--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/
--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/");
cr.DisplayCredits();
System.out.println(" Thank you for playing in this Arcade, "+Username+"\nThis program will
end now.");
break;
else //if inputted command doesn't exist in the game
System.out.println(" ¯\\_(ツ)_/¯ Hmmmmmm, I don't think such a command exists in this game.
Please check your spelling and try again");}}}
Class RockPaperScissors:
import java.util.*; //importing utility package as it helps us accept input from the user and
cause delay in the program
public class RockPaperScissors
public char user_choice=' ';
public int computer_choice=0;
public int NumberOfRounds=0;
public int GamesPerRound=0;
public int Round_Control=0, Game_Control=0;
public int user_score=0, comp_score=0;
public int RPS() //method where Rock, Paper, Scissors! game is carried out
{ Scanner sc=new Scanner(System.in); //creating object sc of Scanner class in order to
accept input from the user
System.out.println("\t\tROCK PAPER SCISSORS - USER VS. COMPUTER EDITION ");
LeaderBoard lb = new LeaderBoard();
System.out.print("Enter the number of Rounds you would like to play: ");
NumberOfRounds=sc.nextInt(); //Accepting number of rounds
System.out.print("\nEnter the number of Games you would like to play in every round: ");
GamesPerRound=sc.nextInt(); //Accepting number of games per round
for(Round_Control=0;Round_Control<NumberOfRounds;Round_Control++) //loop to control
the number of rounds {
System.out.println("********************************************************************");
for(Game_Control=0;Game_Control<GamesPerRound;Game_Control++) //loop to control the
number of games per round {
computer_choice=(int)Math.round(Math.random()*2+1); //assigning random value to
computer_choice
System.out.println("Round "+(Round_Control+1)+", Game "+(Game_Control+1)); //displaying
the current round number and game number
System.out.print("Computer has chosen. Enter your choice :\n");
//the following commands delay the program by 1 second each and display "Rock, Paper,
Scissors! " in an animated fashion
try{ Thread.sleep(1000);
System.out.println("Rock");}
catch(Exception e){
System.err.println("ERROR");}
try{ Thread.sleep(1000);
System.out.println("Paper"); }
catch(Exception e){
System.err.println("ERROR"); }
try{ Thread.sleep(1000);
System.out.println("Scissors!"); }
catch(Exception e) {
System.err.println("ERROR"); }
//accepting input from the user
user_choice=sc.next().charAt(0);
//converting the user's input to lowercase if it is in uppercase
if(user_choice>=65 && user_choice<=90)
user_choice+=32;
switch(user_choice) //checking the user's input to see if it matches the following cases{
case 'r': //if user entered rock
if(computer_choice==1) {
System.out.println("Computer chose -> Rock");
System.out.println("You chose ------> Rock\nResult = TIE <");
System.out.println("-------------------------------------------------------------------");}
if(computer_choice==2){
comp_score+=1;
System.out.println("Computer chose -> Paper");
System.out.println("You chose ------> Rock\nResult = Computer WINS <");
System.out.println("-------------------------------------------------------------------");}
if(computer_choice==3){
System.out.println("Computer chose -> Scissors");
System.out.println("You chose ------> Rock\nResult = User WINS <");
user_score+=1;
System.out.println("-------------------------------------------------------------------");}
break;
case 'p': //if user entered paper
if(computer_choice==1){
System.out.println("Computer chose -> Rock");
System.out.println("You chose ------> Paper\nResult = User WINS <");
user_score+=1;
System.out.println("-------------------------------------------------------------------");}
if(computer_choice==2){
System.out.println("Computer chose -> Paper");
System.out.println("You chose ------> Paper\nResult = TIE <");
System.out.println("-------------------------------------------------------------------");}
if(computer_choice==3){
System.out.println("Computer chose -> Scissors");
System.out.println("You chose ------> Paper\nResult = Computer WINS <");
comp_score+=1;
System.out.println("-------------------------------------------------------------------");}
break;
case 's': //if user entered scissors
if(computer_choice==1){
System.out.println("Computer chose -> Rock");
System.out.println("You chose ------> Scissors\nResult = Computer WINS <");
comp_score+=1;
System.out.println("-------------------------------------------------------------------");}
if(computer_choice==2){
System.out.println("Computer chose -> Paper");
System.out.println("You chose ------> Scissors\nResult = User WINS < ");
user_score+=1;
System.out.println("-------------------------------------------------------------------");}
if(computer_choice==3){
System.out.println("Computer chose -> Scissors");
System.out.println("You chose ------> Scissors\nResult = TIE <");
System.out.println("-------------------------------------------------------------------");}
break;
default:
System.out.println("Invalid input.\n"); //if user entered an invalid value }
System.out.println();
try{Thread.sleep(5000);}catch(Exception e){
System.err.println("ERROR");}}}
user_score*=100;
comp_score*=100;
//multiplying the user's score and computer's score by 100 in order to get the final score
System.out.println("You have scored: "+user_score);
System.out.println("Computer has scored: "+comp_score); //displaying the final scores
//displaying who won/who lost/if it is a tie
if(user_score>comp_score){
System.out.println("Congratulations! You've won against the computer! ");}
else if(user_score==comp_score)
System.out.println("It is a TIE");
else
System.out.println("The Computer has won against you.");
return user_score; //returning the value to the calling method
}}
Class GuessTheNumber:
import java.util.*;
public class GuessTheNumber {
public int User_Score = 0; //public variable
public int GTN() {
System.out.println("--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--
/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/");
Scanner sc = new Scanner(System.in); //creating object sc of Scanner class in order to
accept input from the user
System.out.println("\t\tGUESS THE NUMBER");
double RandomNumber = Math.random() * 100; //generating a random number between
0 and 100 for the user to guess
int RandomNumber_int = (int) RandomNumber; //converting the randomnumber from
double data type to int data type
System.out.println("Computer has selected the number at random");
int tries = 0, userinput = 0;
System.out.println("The number is somewhere between 0 and 100");
System.out.println("Good luck, you may start guessing now ");
for (; userinput != RandomNumber_int;) //loop to begin guessing, only terminates when
the user guesses the number
{ System.out.print("Enter your guess: ");
userinput = sc.nextInt(); //user inputs their guess
//checking if the user's guess equals the random number
if (userinput == RandomNumber_int) {
tries += 1;
System.out.println("Congratulations! You guessed the right number. It was " +
RandomNumber_int);
if (tries == 1)
System.out.println("You took " + tries + " try in order to guess it. ");
else
System.out.println("You took " + tries + " tries in order to guess it. ");
break; //if the user has guessed the random number, then exit the loop}
if (userinput > RandomNumber_int) {
System.out.println("The number you've chosen is higher than the random number
generated");
tries += 1;
continue; //If the user guesses a number higher than the random number, then inform
user that their guess is higher than the random number
if (userinput<RandomNumber_int) {
System.out.println("The number you've chosen is lower than the random number
generated ");
tries += 1;
continue; //If the user guesses a number lower than the random number, then inform
user that their guess is lower than the random number
}}
if (tries == 1) //if the number of tries is 1
User_Score = 240000; //the user's score is 240000
if (tries<= 5) //if the number of tries is less than or equal to 5
User_Score = 9000; //the user's score is 9000
if (tries > 5) //if the number of tries is greater than 5
User_Score = 4000; //the user's score is 4000
System.out.println("You have scored : " + User_Score); //print the User's score
return User_Score; //return the value of the User's score to the calling method
}}
Class LeaderBoard:
import java.util.*; //importing utility package as it helps us to accept input from the user
public class LeaderBoard {
RockPaperScissors rps = new RockPaperScissors();
GuessTheNumber gtn = new GuessTheNumber(); //creating objects of classes
RockPaperScissors and GuessTheNumber in order to access member methods
public String Username = "";
Scanner inp = new Scanner(System.in); //creating object inp of scanner class in order to
accept input from the user
public String inputUserName() //method to accept the username of the user
{
Username = inp.next().trim();
return Username;
public void LeaderBoardMode() //method to play leaderboard mode
System.out.println("-----------------LEADERBOARD MODE-----------------");
System.out.println("\nWelcome to LeaderBoard mode.\n\nIf you select this option, you
must complete the hardest challenge in the game in order to complete it.\n\n There's no
turning back");
System.out.println("You will be challenged to play 1 game of Rock, Paper, Scissors!
followed by another game of Guess The Number!");
System.out.println("Within these two games, try and see if you can make it onto the
leaderboard");
System.out.println("Press the 'e' key to continue....");
char input = inp.next().charAt(0);
int LeaderBoardScore = 0;
if (input == 'e' || input == 'E') //print current leaderboard stats if input is 'e' or 'E'
System.out.println("Current leaderboard stats: ");
System.out.println("----------------- LEADERBOARD ----------------- ");
System.out.println(" Neeraj ------------------------------ 5000 ");
System.out.println("Are you ready for the challenge? Press 'E' again to continue ");
input = inp.next().charAt(0);
if (input == 'e' || input == 'E') //initiate leaderboard mode if input is 'e' or 'E'
System.out.println("Leaderboard mode ----------- [Initiated]");
LeaderBoardScore = (rps.RPS() + gtn.GTN()); //the final leaderboard mode score is
calculated from the individual scores of one playing of Rock, Paper, Scissors! followed by
one playing of Guess The Number!
//printing leaderboard according to the User's score
if (LeaderBoardScore >= 5000) {
System.out.println("----------------- LEADERBOARD ----------------- ");
System.out.println(" " + Username + "---" + LeaderBoardScore);
System.out.println(" Neeraj --- 5000 ");
} else {
System.out.println("----------------- LEADERBOARD ----------------- ");
System.out.println(" Neeraj --- 2000 ");
System.out.println(" " + Username + "---" + LeaderBoardScore);
}}}
else
System.out.println("Invalid input. Leaderboard mode is terminated. Type -ldrbrd again in
order to restart it"); //If the user does not enter 'e' or 'E', then Leaderboard mode will be
terminated and has to be restarted by typing -ldrbrd again, the same is printed on the
screen
Class Rules:
public class Rules {
public void RPSrules() //method to display the rules of the game Rock, Paper, Scissors!
System.out.println("The rules for Rock, Paper, Scissors! are simple:\n\n->The User enters
\n 1.'r' or 'R' for Rock, \n 2.'p' or 'P' for paper and \n 3.'s' or 'S' for Scissors.\n\n-> How to
win: \n 1. Rock defeats Scissors\n 2. Scissors defeats Paper\n 3. Paper defeats Rock");
System.out.println("\n->The Computer's choice is randomly generated. The user's choice
has to be entered for every game in the round.\n\n-> The total scores of both User and
Computer, as well as the final result, will be declared once the game is over");
System.out.println("\n->The Points System: \n1. 1 point will be awarded to the winner
after each game.\n2. In the event of a tie, neither the user nor the Computer will be
awarded a point.\n\n->Once you've played a game against the computer, you have to
wait for 5 seconds for the next round to begin.");
public void GTNrules() //method to display the rules of the game Guess The Number!
System.out.println("The rules for Guess The Number are:\n-> The computer chooses a
random number between 0 and 100(Inclusive of 0 and 100)\n and you must try to guess
the number in the least number of attempts possible.");
System.out.println("The lesser number of attempts you take, the higher your score will
be. ");
}}
Class HelpCommands:
public class HelpCommands {
public void DisplayCommands() //method to display commands required to navigate
through the game
System.out.println("List of commands:\n-> -rps [Initiate Rock, Paper, Scissors! Game]\n-
> -gtn [Initiate Guess The Number! Game]");
System.out.println("-> -rulesRPS [Displays the rules for Rock, Paper, Scissors!]\n-> -
rulesGTN [Displays the rules for Guess The Number!]\n-> -ldrbrd [Initiates Leaderboard
mode]\n-> -crdts [Shows credits of the game]");
System.out.println("Please Note - the above commands are not case-sensitive ");
}
Class Credits:
public class Credits {
public void DisplayCredits() //method to display credits of the game
System.out.println("\t\t--------------------CREDITS--------------------");
System.out.println("\t\"Neeraj's Arcade\" is a project developed by Neeraj Prasanna of
Grade 11, NPSI Chennai.");
System.out.println("\t Project Version ---------------- 1.0.24.08 ");
System.out.println("Designed with BlueJ ------- Version 4.1.4 ");
System.out.println("N.P Virtual Games - 2021 [All Rights Reserved]");}}
SCREENSHOT
OUTPUT
Sample Game 1 – Rock, Paper, Scissors!:
Sample Game 2 – Guess The Number!:
Sample Game 3 – Leaderboard mode :
Sample Output 1 : -exit command
Sample Output 2 : -help command
Sample Output 3 : -rulesRPS command
Sample Output 3 : -rulesGTN command
Sample Output 3 : -crdts command
Sample Output 3 : Invalid command
BIBLIOGRAPHY
•GeeksForGeeks: https://www.geeksforgeeks.org/
•Computer Science with Java: Class 11, by Sumita Arora