In this post, I will be sharing with you an awesome “Hand Cricket Game” project created by me in Java Programming Language. I created this project years ago during my school days. This is just one of the many Java projects that I created. I used BlueJ to compile and run these Java programs and I recommend you to do the same.
Here is a short explanation by me about Hand Cricket:
Hand Cricket is a very famous game among the school kids in India and similar countries. Traditionally, there are two players who will be playing the game, and after performing a ‘toss’, one chooses to bat and the other has to bowl. Both the players will (through hand gestures called ‘throws’) simultaneously signify a number between 1 to 10. If both the players point out the same number, the player who is batting gets ‘out’, else, this is repeated and whatever number the batting player (batsman) keeps throwing are added and that becomes his/her score.
After the batsman gets out, the bowling player (bowler) becomes the batting player and vice-versa. Now, the process is repeated again and finally, if the original bowler scores more than the original batsman, he wins. If they both score the same runs and both get ‘out’, then it is declared as a tie. If the original batsman scores more than the original bowler, he wins. Simple as that. I hope you understood.
![]()
![]()
Below, I have uploaded a video of some Indian guys having a lot of fun playing “Odd-Even Team Hand Cricket Game”. If you have never heard of Hand Cricket in your life, you should definitely watch this video! It will surely cheer you up.
![]()
Now, enough about Hand Cricket and let’s talk about my Hand Cricket Project in Java Language.
Below are some of the purposes for which I have posted this project/assignment on this blog:
- To provide for class X (10th standard) or class XII (12th standard) computer applications project in Java for ICSE, CBSE, HSC etc. students (especially in India)
- To provide for any other class’ or standard’s java project required by school or college students of any board (especially in India)
- To give an idea to the people about how creative one can be in Java programming
- To provide an insight as to how the beautiful game called “Hand Cricket” can be implemented into Java
I am allowing you guys to use/download this project created by me for completely free! This is a “free royalty free project“. Yeah, that’s right fellas! It means that there is no need to credit me anywhere. Take all the credit for making this program in Java all by yourself if that pleases you.
Here you go!
Input Code:
// Program written by The Adarsh Mehta // www.theadarshmehta.in import java.io.*; public class Playing_Hand_Cricket_Against_Computer { public static void main(String args[])throws IOException { InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr); String name; // to accept the player's name; int aa; // converting the random real number generated by 'rr' into a random whole number run for the computer; int ii; // used in for loops; int bb; // to accept the player's number; double rr; // to generate a random real number; int cheat; // to end the game if wrong input is entered; to keep a check whilst the game is running as to whether the game has ended or not; int score1; // to store the latest runs scored by the player; int score2; // to store the latest runs scored by the computer; int c; // used in for loops to create a specific design; int choice; // used to decide whether the game needs to be ended or restarted; int infinity=1; // used to keep the game running until the player decides to end the game; /* After referring to all the comments mentioned above, * you must be able to understand the working of this program as it is very easy. * If you find it complicated, * feel free to visit www.theadarshmehta.in * and contact The Adarsh Mehta. * Have fun! */ while(infinity>0) { name=" "; aa=0; ii=0; bb=0; rr=0; cheat=0; score1=0; score2=0; c=0; choice=0; infinity=1; System.out.println("======================="); System.out.println("| WELCOME TO THE GAME |"); System.out.println("======================="); System.out.println(""); System.out.print("Enter Your Name: "); name=br.readLine(); for(c=0;c<=2;c++) { System.out.println("===================================="); } System.out.println("Hello "+name+","); System.out.println("."); System.out.println("WELCOME TO THE CRICKET-MANIA"); System.out.println("."); System.out.println("Instructions:"); System.out.println("."); System.out.println("This Game Is Similar To The Hand-Cricket Game Played By Kids."); System.out.println("."); System.out.println("There Is No Limit On The Number Of Balls."); System.out.println("."); System.out.println("You Will First Bat. Enter Any Number From 1 To 10."); System.out.println("."); System.out.println("Enter The Numbers Carefully Without Making Any Mistake."); System.out.println("."); System.out.println("If The Number Entered By The Computer Is Same As The Number Entered By You,"); System.out.println("You Will Be Declared As Out."); System.out.println("."); System.out.println("Your Final Score Will Be The Sum Of The Numbers You Entered Before Getting Out."); System.out.println("."); System.out.println("After Getting Out, You Will Have To Bowl."); System.out.println("."); System.out.println("Try To Enter A Number Similar To The Number Entered By The Computer."); System.out.println("."); System.out.println("If The Sum Of Numbers Entered By The Computer Becomes More Than Your Score, It Will Win."); System.out.println("."); System.out.println("But If You Enter A Number Same As The Number Entered By The Computer, You Can Win!"); System.out.println("."); for(c=0;c<=2;c++) { System.out.println("===================================="); } System.out.println("YOU ARE BATTING:"); for(c=0;c<=2;c++) { System.out.println("===================================="); } for(ii=1;ii>0;ii++) { System.out.println(""); System.out.print("Enter Your Number: "); bb=Integer.parseInt(br.readLine()); rr=((Math.random())*10); rr=rr+1; aa=(int)(rr); System.out.println(""); System.out.println("Computer's Number: "+aa); System.out.println(""); System.out.println("**********"); System.out.println(""); if(bb==aa) { System.out.println(" "); System.out.println("HOWZATTT!!!!!!"); System.out.println(" "); System.out.println("################"); System.out.println("################"); System.out.println("YOUR FINAL SCORE = "+score1); System.out.println("################"); System.out.println("################"); System.out.println(" "); break; } else if(bb>0&&bb<=10) { score1=score1+bb; } else if(bb>10||bb<=0) { for(c=0;c<=2;c++) { System.out.println("===================================="); } System.out.println("You have either tried to cheat or entered a wrong input. Game Over!"); cheat++; break; } System.out.println("Your Current Score Is "+score1); System.out.println(""); System.out.println("**********"); } for(c=0;c<=2;c++) { if(cheat>0) { break; } System.out.println("===================================="); } for(c=0;c<1;c++) { if(cheat>0) { break; } System.out.println("YOU ARE BOWLING:"); } for(c=0;c<=2;c++) { if(cheat>0) { break; } System.out.println("===================================="); } for(ii=1;ii>0;ii++) { if(cheat>0) { break; } System.out.println(""); System.out.print("Enter Your Number: "); bb=Integer.parseInt(br.readLine()); rr=((Math.random())*10); rr=rr+1; aa=(int)(rr); System.out.println(""); System.out.println("Computer's Number: "+aa); System.out.println(""); System.out.println("**********"); System.out.println(""); if(aa==bb) { System.out.println(" "); System.out.println("COMPUTER IS OUTT!!!!"); System.out.println(" "); System.out.println("################"); System.out.println("################"); System.out.println("COMPUTER'S FINAL SCORE = "+score2); System.out.println("################"); System.out.println("################"); System.out.println(" "); break; } else if(bb>0&&bb<=10) { score2=score2+aa; } else if(bb>10||bb<=0) { for(c=0;c<=2;c++) { System.out.println("===================================="); } System.out.println("You have either tried to cheat or entered a wrong input. Game Over!"); cheat++; break; } if(score2>score1) { System.out.println(" "); System.out.println("THE COMPUTER HAS SCORED MORE THAN YOUU!!!"); System.out.println(" "); System.out.println("################"); System.out.println("################"); System.out.println("COMPUTER'S FINAL SCORE = "+score2); System.out.println("################"); System.out.println("################"); System.out.println(" "); break; } System.out.println("Computer's Current Score Is "+score2); System.out.println(""); System.out.println("**********"); } for(c=0;c<=2;c++) { if(cheat>0) { break; } System.out.println("===================================="); } for(ii=0;ii<1;ii++) { if(cheat>0) { break; } System.out.println(" "); System.out.println("################"); System.out.println("################"); System.out.println("YOUR FINAL SCORE = "+score1); System.out.println("COMPUTER'S FINAL SCORE = "+score2); System.out.println("################"); System.out.println("################"); System.out.println(" "); if((score1)>(score2)) { System.out.println("Congratulations "+name+"!! You Have Defeated The Almighty, Computer!!"); } else if((score1)<(score2)) { System.out.println("Sorry "+name+", But The Computer Has Defeated You..!"); } else { System.out.println("It's a Tie..! :("); } } for(c=0;c<=2;c++) { System.out.println("===================================="); } System.out.println(""); System.out.println("Enter 1 To Play This Game Again."); System.out.println(""); System.out.println("Enter 0 Or Any Other Number To Quit."); choice=Integer.parseInt(br.readLine()); System.out.println(""); if(choice==1) { System.out.print('\f'); } else { System.out.print('\f'); System.out.println("Good Bye!"); break; } } } } // Program written by The Adarsh Mehta // www.theadarshmehta.in
Output:
=======================
| WELCOME TO THE GAME |
=======================
Enter Your Name: Adarsh
====================================
====================================
====================================
Hello Adarsh,
.
WELCOME TO THE CRICKET-MANIA
.
Instructions:
.
This Game Is Similar To The Hand-Cricket Game Played By Kids.
.
There Is No Limit On The Number Of Balls.
.
You Will First Bat. Enter Any Number From 1 To 10.
.
Enter The Numbers Carefully Without Making Any Mistake.
.
If The Number Entered By The Computer Is Same As The Number Entered By You,
You Will Be Declared As Out.
.
Your Final Score Will Be The Sum Of The Numbers You Entered Before Getting Out.
.
After Getting Out, You Will Have To Bowl.
.
Try To Enter A Number Similar To The Number Entered By The Computer.
.
If The Sum Of Numbers Entered By The Computer Becomes More Than Your Score, It Will Win.
.
But If You Enter A Number Same As The Number Entered By The Computer, You Can Win!
.
====================================
====================================
====================================
YOU ARE BATTING:
====================================
====================================
====================================
Enter Your Number: 5
Computer’s Number: 9
**********
Your Current Score Is 5
**********
Enter Your Number: 5
Computer’s Number: 10
**********
Your Current Score Is 10
**********
Enter Your Number: 5
Computer’s Number: 7
**********
Your Current Score Is 15
**********
Enter Your Number: 5
Computer’s Number: 5
**********
HOWZATTT!!!!!!
################
################
YOUR FINAL SCORE = 15
################
################
====================================
====================================
====================================
YOU ARE BOWLING:
====================================
====================================
====================================
Enter Your Number: 5
Computer’s Number: 9
**********
Computer’s Current Score Is 9
**********
Enter Your Number: 10
Computer’s Number: 6
**********
Computer’s Current Score Is 15
**********
Enter Your Number: 5
Computer’s Number: 8
**********
THE COMPUTER HAS SCORED MORE THAN YOUU!!!
################
################
COMPUTER’S FINAL SCORE = 23
################
################
====================================
====================================
====================================
################
################
YOUR FINAL SCORE = 15
COMPUTER’S FINAL SCORE = 23
################
################
Sorry Adarsh, But The Computer Has Defeated You..!
====================================
====================================
====================================
Enter 1 To Play This Game Again.
Enter 0 Or Any Other Number To Quit.
0
Good Bye!
Wrapping Up
Copy and paste this program code into BlueJ or any other similar software, compile it, run it and test it out! If you play this game smartly, and you will most likely win majority of the times because we are obviously smarter than these puny computers.
Comment below if you face any problems or errors while running this piece of code and I’ll be more than happy to solve your queries. I normally ask you all to share my posts with your friends but in this case, I will not because you wouldn’t do it anyways, would you? It is too valuable to be shared with people around you as it will then make it clear that you did not write it.
![]()
Thank you.
LINK TO THIS POST:
<a href="https://www.theadarshmehta.in/blog/hand-cricket-project-in-java/2015/12">Hand Cricket Project In Java (BlueJ)</a>

Friend, I want to say something..in addition to what you have programed…. I also have programed a cricket game in bluej yesterday. But I wanted to make a real cricket game(Non-graphical as I know almost nothing about graphics. I read in class 11(ISC) at present. I implemented the knowledge which I have acquired through class 10(ICSE)….To make it more realistic you may reduce the score to 6 and the user may make 3 and 5 very rarerly(I have used Math.random()) . Your program to out the batsman is same as mine. I have made infinite bowls to 5 overs only….You may make it for 10 and 15 overs and test match(user will choose which type of match he or she will play) and introduce defensive stroke(0 run) and not out(Computer’s 0 score will match it once in 30 times use random function here too). Please don’t take it as criticism…take it as suggestion….KEEP GOING MAN…YOU HAVE DONE A GREAT JOB…CONGRATS..
Miraculous program Adarsh
Awesome, I was learning Java programming and I made the same project as well (Before looking into your code). Was just hanging around in the web to see other people’s codes. It’s really nice and creative. There’s a loophole in your program though! If I enter any number more than 10, I’ll never get out, and hence I can score as many runs as I can. Also, feel free to contact me if you want to collaborate and make something more creative and usable (like playing over networks or adding graphics or other stuff in this). Also, I’ve seen your details and seems like you’re 3 years elder than me, so perhaps you might’ve graduated. Do you mind me asking what is your major? If it’s computer science or similar, it would be great, because I’m pursuing Computer science as well! Hope to collaborate with you!
there are some errors plz solve then in the starting of the code
hi
can i get the flowchart and algorithm on hand cricket project in java using source code
Please make the flowchart of hand cricket programming!.. I am really in need for it…
what is the function of /f in the last and the purpose of cheat in the last can u tell me
what is the function of /f in the last
This enables us to move the cursor down.
Bro u have more games programs with u. I need to do 3 games and I’ve done 1 now
Can you share me the code
I am a master of hand cricket. Very few people can defeat me.
SORRY TO SAY ! BUT MY HAND CRICKET PROGRAM IS MORE EFFICIENT THAN YOURS .
Oh can you share me your code
pls send me a code
This is great!
may i know where’s the variable discription
the dude used comments , so no variable description
HI ADARSH , I NEED A HELP I WANT TO MAKE MOBILE SHOWROOM PROGRAM BUT I CANNOT ABLE TO DO IT PLEASE CAN YOU MAKE A SHOT PROGRAM FOR PLEASE
Bro please explain me how to generate a whole number in bluej……and yes your program is awesome
import java.util.*;
{
public static void main(int n)
{
for(int i=0;i<=n;i++)
{
System.out.println(i);
}
}
}
You have forgot the class
hello adarsh dude, i have atlast scored a century on the hand cricket thanks for this awesome game man.please create more interactive games like this
please make more programs like this i am also looking forward for some graphic interface games,and thank you for this program
Your program is awesome.
Can you please mention the purpose of your methods and classes in your program.
i need documentation of this please very urgent plz help me!
Thank you it helped me a lot the program is awsome
thanks a lot again
Thank you it helped me a lot
Awesome programming skills! Thanks for taking time to publish it online for us!
And even more thanks for a simple, non-complicated version of this.
I needed variable discription for the program
IT IS VERY IMPORTANT
hi Adarsh…
I went through the programe it is quite interesting and u can make few changes in it if u want….i.e, giving team option and u can also use switch case or scanner class to make it less complicated…
doing a programe so big there will be some errors can u tell me how many times did u check for errors…Which college r u
GOOD WORK
Can you please tell the variable description of this program . Do you have any other program of less than of 100 lines , because I wrote a program which has a lot of errors and I can’t fix it .
This program helped me a lot .
thank you……………………
hi Adarsh you can make this program better by making a toss system where you can choose to bat or to bowl
Hi adarsh you are really good in programming bro…
wow great ..i am a class 8 student and it worked ….thnxs brother……..
what is the use of /f in the last…………………its urgent pls tell it fast
i just want this program algorithm
please me this program algorithm please
Its awesome game I am really enjoying it actually we have got a project on this and after doing this I have got full marks thanks bro
Very very happy to hear that Aneesh. Glad you had fun with it.
Thank you.
Hey Adarsh,
You’re Quite Brilliant. I Love Java Programming. And The Best Way To Get Guidance In It Is From You. Your Cricket Game Is Awesome. Just I wanna Ask You That In The Program, The First Loop You’ve Created(while loop), Why haven’t you’v closed It With Braces ??
One More Thing Can You Tell Me Some Java Typical Programs For Class IX That I Can Practice.
Thank You,
Bro its not working plz tell me where to close the bracket
omg This is coool! thanks for makin’ it!
Always a pleasure!
Thank you.
can you pls mention the methods in your program
Hi. I’m in 10th class. Not bragging but I wrote the same program in 91 lines without using buffer or input string reader. I don’t even know what they are.
Cheers!!
Soham, that IS bragging,
hahaha, but it is completely acceptable.
It’s great you were able to write the same game in like 91 lines without using buffer or input string reader! I am guessing you used ‘scanner’…
And please do know that while writing this program, my aim was not to make it as small as possible. Otherwise, I could have made it very very less in length, as a very good portion of my program is filled with designs and explanations and blank lines and other fancy stuff which just makes my program look neat and tidy, easily understandable and lengthy. While submitting projects, these factors are also important and so only reducing the length of the program as much as possible is not of utmost importance, at least not at 10th Standard Level.
I would really like it if you share your program code with us.
Thank you.
Haha, yes I did use Scanner. And I got your point. I was hesitant to give my code because this is my boards project but then, your’s is quite the same. So here it is –
https://pastebin.com/yssD5gUx
I have checked and it is fine. Good work bro.
And I have also replied to you by email about the issue you were facing.
Thank you.
Sir , can u please upload a switch case program of 300 lines??
I would be highly obliged if u do so.
With regards,
Sarthak Sharma.
Hi sir I am honey. I need your phone number to talk with you. Can I get please
Surely, Honey! I have emailed you my mobile number.
Thank you.
Please extend this hand game programming
Hi Aadarsh,
You hv done a Great work in making this project.
I am in 10th icse and have a project topic regarding the online fantasy cricket game( just like Dream 11) but I do not know where to start from.
Can U plz give some ideas??
Can u tell me of how many lines the program is ?
Plz can u reply fast as it’s urgent!
Hello, Shreya.
This program is of approximately 285 lines.
Thank you.
My JDK is 7 and when I paste the program and tried to run in BlueJ then asks for input
Please watch this video and follow the steps, ditto:
https://www.youtube.com/watch?v=WZT4b0wJ5co
I am confident it will solve your problem.
Thank you.
Sir, your game is really nice.
Very happy to hear that! ^_^
Thank you.
Sir your program is very good but I have got a project of making a program of 40 pages on any of the topics
Ipl
online ticket
dominos
pizza hut
But I’m not getting that how can I make a program on these programs
Hello, Nameer.
First of all, gracias for giving a compliment on my program. Means a lot to me.
All the four topics that you have mentioned are great choices. You can choose any one of them and you will be just fine!
Me, personally, would go for either Dominos or Online Ticket.
Just sit and plan all the options and details that will come into the program, and then prepare a nice flow-chart to demonstrate it neatly on a piece of paper. Keep on adding more and more options and details at each level so that when you convert your flow-chart into a real program, your program code is lengthy enough to fill the 40 pages…
If you face any difficulties while writing the program code or have any other doubts or questions, feel free to comment.
Thank you.
Hey adarsh in bluej this program is not showing void main() option. What to do?
Nice programming!!!!!!!!!!!!!!!
BGW
Thank you.
Hey give me you email (or just email me) and I’ll send you my programs and you tell how they are. I am in 10 th std ICSE, can you recommend me any good program I should make for my project.
Sorry for replying so late, Mitul. Your comment had just escaped my eyes.
My email id is [email protected]. Feel free to send me anything you want. I am not as free as I’d like to be right now, but I’ll try my best to reply within a few days after checking out your program.
And regarding choosing a nice topic for your project, please go through the other comments on this post and I am sure you will find a good idea.
Thank you.
It is a very good program. Very interactive.
Hats off to you bro.
Appreciate these kind words, brother Nimish. Glad you took some time to make this wonderful comment.
Thank you.
Hello.
Many many thanks for your idea. I’ve tried it but in scanner class and a little differently. But anyways, thank you very much for the concept of this game. I was finding some simple game to build on java and this is quite nice and easy. So thank you very much!!!!!
Happy to help.
And it’s nice to hear that you improved this code by making a few changes on your own. A few people just copy-paste my code as it is and do not work a tad bit on it. Glad to see that you’re not one of them.
Thank you.
Hello I was not able to play any further when I entered my name
I am sorry to hear that, brother.
Please watch this video and follow each and every step carefully to try to solve your problem:
https://www.youtube.com/watch?v=WZT4b0wJ5co
If you still face any problems, please explain the error you are facing in detail and I’ll be more than happy to help.
Thank you.
sir, i am not able to understand that how it is logically made by you.I also need to know its alogrithm(steps or the logic applied).
ill be thank full if help me.
ILL BE THANKFUL IF U HELP ME………..
I AM IN CLASS 10 AND I HAVE TO MAKE A PROJECT (java)ON WORKING OF PAYTM……….
Hello, Pooja or Ananya (whoever you are).
Here is a short explanation by me about the program:
In my program’s source code, the user is first batting and he/she is asked to enter a number. That number is stored in the variable ‘bb’. After that, a random number between 1 to 10 (including both 1 and 10) is generated using some mathematical adjustments and functions and stored in the variable ‘aa’. Using if-else, then, it is checked if bb is equal to aa or not. If they are equal, the user is declared as OUT. If they are not equal and the user’s input is between 1 to 10 (including both 1 and 10), then the number entered by the user is added to his/her total score (in the variable ‘score1’). Once the user enters the same number as the computer has generated, he/she is declared OUT and then the computer goes to BATTING.
After that, still, the numbers entered by the user on each THROW is stored in the variable ‘bb’. The random numbers are still stored in ‘aa’. Now, if the number entered by the user is equal to the number generated by the computer, the computer is declared as OUT. If they are not equal, then the number generated by the computer is added to its total score (in the variable ‘score2’). Once the user enters the same number as the computer has generated, the computer is declared OUT and then the FINAL SCORES of both the players are compared by comparing the variables ‘score1’ and ‘score2’.
Whoever scored the more, WINS! If they both scored the same unluckily, it is a TIE.
Hope you found this useful. And good luck with your project on PAYTM.
Thank you.
Sir I have made a game based on string handling and related to it. I wished I’d you can just run it and see how it is I m in class 10 ICSE. So can you give me your id to mail the file.
Sure, Aditya.
I would be honored to run your program and check it out.
Please send your program’s source code to [email protected].
I recommend that you paste your source code on http://www.pastebin.com and share the link of your source code web page with me. I promise I will keep your source code confidential.
Thank you.
I need any other similar program in BlueJ
Please check out my other blog post:
Cool Number Guess Magic Trick Java Program (BlueJ Project)
Thank you.
I cannot understand how to run this program… Means that I complied it but not able to run it…
Hello, Mohit.
Please watch this video and see if you are doing anything wrong.
https://www.youtube.com/watch?v=WZT4b0wJ5co
If after watching the video you are still not able to compile and run the program, then please explain your problem and the error faced by you in detail by replying to this comment and I will be more than happy to help.
Thank you.
Could you please get the variable description of this program….. Its really urgent
I have already put most of the variables’ basic purpose and description in the program source code itself. Please check out the program source code. It is written as comments beside the first declaration of each and every variable.
Hope this helps. If you still have any doubts/queries, do not hesitate to reply.
Thank you.
Ok thank you so much, this project helped me a lot to get through my internal marks for my board examinations……. Thank you so much
My pleasure.
Thank you.
Bro I would want to know what is your reason of using buffered reader instead of scanner class anything specific and what would be the programme code in scanner class because I have failed converting it to scanner class and I don’t understand buffered reader
Hello, Virshank. There is nothing specific and you can use any one of the options: Buffered Reader Or Scanner for this program.
I have used Buffered Reader because I know how to use and I do not know as much about Scanner.
But Scanner is generally beneficial and better than Buffered Reader in these types of cases.
So, please visit the below link to understand how to use the Scanner class:
http://www.cs.utexas.edu/users/ndale/Scanner.html
Also, do visit this link if you wish to know several points of comparison between Scanner and Buffered Reader:
http://stackoverflow.com/questions/2231369/scanner-vs-bufferedreader
Thank you.
I have a similar Hand Cricket program (not based on this method) which I coded myself. It uses ‘scanner’ and also has various other choices like heads/tails toss, cheats etc. If you want to see how the program works with Scanner, do let me know.
Sure, Calvin.
I would love to see your program and I am sure others will too. This is a very nice innovation from your side. Please post a link to your program’s source code right here in the comment section and help out our fellow readers! I will surely give you full credit for your program.
Thank you.
Hi Adarsh Mehta
You had made a wonderful program of cricket. My teacher so happy to see this program .
Thank you
I am very happy to hear that, Rohit!
Thank you.
It’s really a fantabulous webpage…!!!!!!!!! As it gives an idea how to play hand cricket for new learners……
Yes, you are very correct Pranati!
Before writing this post, I did give a lot of thought about whether posting this would hinder the learning process of the students – as they will be able to copy and paste this project and not learn anything because they would not work hard on their own. But then, of course, I came to the conclusion that those who wish to learn will learn and those who wish to escape hard work and copy-paste will find some or the other way to do that.
And, after seeing all these comments, I am glad to know that students are not just copy-pasting this Java Program but understanding it in detail and asking nice doubts in the comments section as well as on email. Glad you liked it too!
Thank you.
Work appreciated..
God bless..
This program of yours helped me alot..
Thank you so much!
I appreciate you taking time to write this wonderful comment, brother!
Thank you.
Thank you so much for your help this program helped me alot earlier. I was wondering that how I will make my project but now its done.
I really loved your creation your program was awesome and very easy to understand. I never faced any problem throughout the program.
Thank you soooo much.
I hear that all the time but it never gets old.
Glad to have helped you out! I wish you good luck in all your future endeavours. 
Thank you.
I just have to write 2 paragraphs.
I will be really grateful to you if you will do this for me.
Thanks a lot.
SCOPE.
This Hand Cricket program written by me has a wider scope than one may imagine. Hand Cricket is a very famous game among all the school kids in India and similar countries. School students play it a lot with their friends on a regular basis. This program allows everyone to play the same Hand Cricket game without the need of any other person. So, if someone is alone and still wants to play Hand Cricket, this program offers him/her that opportunity. Also, playing Hand Cricket against Computer interests many people and is quite entertaining and addictive. This program serves that purpose as well.
The Hand Cricket program is also, inter alia, a decision maker. So, if someone is not able to make a decision by himself/herself, he/she can play with the Computer, assign the two choices to win or lose, and make his/her decision. One may argue that this is not a good way to make decisions, but still, it is being practiced by so many people around the world. So, after reading this, you should be able to make out that the Hand Cricket program’s reach is pretty good and it can be seen as a precursor to more complex and better games in Java language.
Thank you.
I need to submit my project on Saturday, plz can you provide me with a written scope of the program?
I could do that if you would be so kind to give me a format and the length of the scope of the program that I have to write for you.
Thank you.
I have made the input limit hundred and the computer number limit as 100 so that I could get a little kick in playing the game…!!! This is an awesome code!!! Fun in playing…
Hahahaha, that surely will make the game very long and risky… Enjoy!!!
I am glad you found my code “awesome”!!!
Thank you.
what to do if you want to change limit of input numbers please tell
NICE ONE BRO…
Thank you.
THANKS BRO , YOU HAVE MADE A GREAT PROGRAM, I’M JUST IMPRESSED… ☺
You are welcome, bro. Comments like these really help me out and cheer me up!
Thank you.
When I type the program, it shows error… Why is it so?
Hello, Mita.
Please watch this video:
https://www.youtube.com/watch?v=WZT4b0wJ5co
If you still face problem after watching that video, then please describe the error in detail so that I can help you.
Thank you.
Thank you so much for this program. My friends and I had spent quite a lot of time writing a program for hand cricket, but had a few problems coming up. This code runs perfectly fine. You really did solve our doubts. I have a question by the way… Here the batsman can score between 1 and 10. If I want the runs between 1 and 6, will multiplying the random number generated with 6 work?
And yes, thanks on behalf of my friends too.
I am very happy to hear that this program helped you all out!
And yes, if you want the runs to be between 1 and 6 (including both the numbers), you can just multiply the randomly generated number by 6, add 1 to it, and then convert it to an Integer. It will work! In fact, you can give the user an option of choosing the range of numbers (like 1 to 9, 1 to 11, and so on) rather than fixing the range of numbers in the program. You can also add more cool features like Odd-Eve toss (for batting or bowling).
Have fun.
Thank you.
PLEASE MAKE ME UNDERSTAND THIS PART IN DETAIL. I SHALL BE GRATEFUL 2 U.
I am a parent of Xth class student – she has taken Computer Application…
Okay…
Thank you.
Hello sir,
I am not understanding why have you used cheat variable in the program in so many places… Can you please explain…???
Sure, Manju. It is pretty simple.
I do not want the user to enter a number which is not a number between 1 and 10. So, if the user enters a number which is not a number between 1 and 10 (say 13), the “cheat” variable becomes greater than 0. And I have put conditions everywhere that if cheat>0, then do not execute that block of code. So, basically, when cheat becomes greater than zero, the programs ends.
You can change this if you want a give the user a chance to enter a new number again, rather than just ending the program.
This is the best I can explain this. If you are still not able to understand, then may God help you.
Thank you.
I still not understood the purpose of using cheat and random
Dear Akaash, the variable named ‘cheat’ is used so that the player does not enter any number less than 1 or any number greater than 10.
So, for example, let’s say the player enters 13, then ‘cheat’ variable’s value changes to 1 and the program ends.
Math.random() function is just used to generate a random number.
Hope this helped you out.
Thank you.
I still could not understand the function of ‘cheat’… I am not able to understand why it is being used and what is its role… Could you please clear my doubt…???
Hello, Biju. Surely I would love to clear your doubt.
I ask the player to enter any number between 1 to 10 (including both). Now, if he tries to act over smart
, and enters, say 20, the ‘cheat’ variable becomes 1. And if you notice, everywhere I have put a condition which checks if ‘cheat’ variable is greater than 0 or not. If it is greater than zero, then “break;” is executed and the remaining part of the program is not executed (because in every part of the code, I have put a condition that if ‘cheat’ > 0, then break).
So, only a message is displayed, saying, “You have either tried to cheat or entered a wrong input. Game Over!”. And then the program ends.
You can modify this if you do not like it. You can set it so that if the user types wrong input by mistake, nothing happens, the game does not end and it still continues.
I hope it is cleared now.
Thank you.
Thank you… My doubt has been cleared…
Do you have any suggestions for creating an additional feature in the above program by adding the odd or even (coin part or toss). This is supposed to be included in the starting. Could you please gimme some ideas?
Sir, I also do not have any idea about how to include appropriate error handling in my hand Base Ball Program.
I’d be very grateful if you would give me some tips on using try and catch blocks in this program in BlueJ. I’m in 10th by the way.
Hello, Vijetha.
You will have to learn the try and catch function yourself and apply it to this program. I am sure it won’t take much time.
I do not have much knowledge about try and catch functions, and because of that fact, I am unable to use them. So, what I do to cover up for that is, I try to eliminate the possibility of errors. Check out my new post: Cool Number Guess Magic Trick Java Program. In that, I have basically eliminated almost all possible errors.
To eliminate all possible errors, here are the things I have to do:
This process does make the code lengthier but comes in handy for people like me who only know the basic functions of Java.
Now, coming to your first problem. I see that you want to add ‘Odd’ or ‘Even’ toss to this program. Well, it is lengthy but very simple. First, ask the user to select ODD or EVEN. Then, tell him to throw a number. Now, generate a random number out of 1 or 2. Add the random number generated to the user’s input. Check using the % function if the remainder after dividing with 2 is 1 or 0. If it is 1, it is odd and the player will choose if he wants to bat or ball, else, the computer will do so. Again, the computer can choose bat or ball by generating a random number (number 1 and number 2 only, no need to generate 10 random numbers). You will probably have to create new two variables (say ‘j’ and ‘k’). Put the YOU ARE BATTING part of the program in a loop with a condition that it only runs if ‘j’ is 1. Put the YOU ARE BOWLING part of the program in a loop with a condition that it only runs if ‘k’ is 1. Put these both loops created by you in another big loop. Now, according to your toss, decide which part of the code should run first by changed the respective variable’s value to 1 first, and then you can run the other part of the code left afterward using that big loop.
I hope you didn’t lose me there.
Thank you.
Thanks a lot!
I also don’t know why you have used this array called ‘args’.
Should i create a different class for the toss thingy to reduce the complexity?
You are welcome dear.
I normally like to stick to one class (because I have never even used two classes together and do not know how to do it, lol) and would recommend you to do the same. I do not think it increases the complexity in any way (it might make the program look untidy). You can do whatever you like, though.
I do not remember why we used to have String args[] in the program. I just followed it as a convention.
Please check out this link to know more about it:
http://stackoverflow.com/questions/890966/what-is-string-args-parameter-in-main-method-java
Thank you.
Could you please send me a source code for rock paper scissors?
I have not written any code on Rock-Paper-Scissors.
I had only suggested Soumyaa, in the comments, a few topics on which she could make her Java project, one of which, was Rock-Paper-Scissors.
Sorry to disappoint you Biju.
But it is not at all complicated to write a code on it. I would urge you to do it yourself. Just ask the user to enter ‘R’, ‘P’, or ‘S’. Generate a random number from the computer’s side (only 1, 2 or 3) and assign each number to a different weapon. Use if-else condition statements to count the scores and you may limit the total scores (for example, the first player to score 10 wins).
Thank you.
I received your email Biju, asking me how to generate a random number between 1 and 3.
Well, long story short, you can use the following piece of code to generate a random number (natural number only) between 1 and 3 (both inclusive):
I hope this satisfies your queries.
Also, I recently published a new post on my blog – Cool Number Guess Magic Trick Java Program. I thought you might find it of some use. It is also a kind of Java project, you can say.
Thank you.
Sir, I am a student of 10th grade.
I was going through your hand cricket coding. I have a few doubts. Kindly clear them.
They are:
“rr=((Math.random())*10);
rr=rr+1;
aa=(int)(rr);”?
Hello, Biju.
I am glad that you have decided to understand my program completely and not just blindly copy it. I admire that.
I have tried my best to clear your doubts below:
Now, the random number generated before was only between 0 and 1, and did not include 1 itself. So, ‘rr’ could be ‘0.something’ or ‘9.something’ but not ’10.something’. Because of this fact, when I used the ‘aa’ integer variable to convert the ‘rr’ number to an integer, it could turn out to be zero sometimes! Also, it could never turn out to be 10. Because of this reason, I have first added 1 to the ‘rr’ and only then proceeded to convert it into an integer. After doing all this, now the number could never be zero and could be ten.
I hope you understood my explanation and are satisfied with it.
Thank you.
Hi sir… I am Soumyaa and I’m in 10th.
I am making a java project on games… And I need to make 3 games at least…
I have managed 2 (hand cricket and the other on memory boosting).
Then I thought of tic tac toe… But that would make the programme too big…
Can you please suggest such a game that is not too long… It would be kind of you…
And thanks a lot for the hand cricket program…
And one more thing
No applets please…
Hello, Soumyaaaaa
Tic Tac Toe is a great great idea for a student at your level. So I would urge you to do it. I do not think it would turn out to be very lengthy or difficult. I think you would be fine just using three arrays containing three elements each to simplify it. I guess it would take you around 12-14 hours in total to make it (unless you are a slow typer
).
But, I do not want to leave you hanging. So, if for some reason you still do not like the idea of implementing Tic Tac Toe in your project, here are some other unique Java Game project topics from my side (I could only think of these four
):
I hope you select the one which suits you best!
Thank you.
Thanks a lot sir… I think I should be going for tic tac toe only…
And sir, the other options are quite relevant but hangman has already being chosen by one of my classmate and maths calculation too…
And rock paper scissors would be somewhat similar to hand cricket…
And sir please one more help…
I have made the program only tic tac toe part isn’t there…
I wud like you to have a look at it and tell me if there is any flaw in it…
If you have time I would be glad to mail it to you…
So please give me your mail id…
And once again, thank you…
I received your mail Soumyaa.
I do not have enough time to constructively analyze your program. So, I just ran it in BlueJ and tried to play the first two games multiple times.
There are many many problems in your program. I do not have time to list them all in this comment, but here are some of them:
I hope you have enough time to fix all these problems. I would really recommend dropping the idea of Tic Tac Toe if you can, and focusing on making the project with these two games only, and making them perfect. I remember I had only two games (Quiz and Hand Cricket) in my project during my school days, but they were 100% perfect. And I can assure you, I got EXCELLENT marks!
I am sure you won’t need my help from now on (I don’t have any time to help anyways till November 8th), because you can just run your program yourself and try different possible inputs to see if your program is able to handle them all and work correctly no matter what input is entered.
I hope you got my point.
Thank you.
Sir, I got your point
and the errors have been sorted out
and the toss thing was like the toss we do in normal play…
Choose Odd or Even number,
take out random numbers and just add them up… It was just the thing that my instructions were not clear…
Thanks for your help… And yeah now don’t require any help…
I know what the toss thing is in Hand Cricket Soumyaa. I liked your idea of implementing such a nice feature into that game.
And in my previous comment, I was just mentioning that after running the code you sent me, after playing the hand cricket game, after selected Odd or Even and after entering a number, the game would just end. Maybe in the code you sent me, you had not completed the toss part. I haven’t had any time to check that.
Anyways, good luck with your project.
Hope you sorted everything out properly.
Thank you.
Yeah its all done.
As you know in programing smallest error can make a huge difference!
And all the best for your studies… And exams…
Thank you.
Sir, I want the source code or at least the rough draft for hospital management.
Hello, Srujana.
Here is the semi-complete draft code I have written on hospital management just for you (and two other people):
http://pastebin.com/V1Dmsq3s
Also, here is an image demonstrating a basic understanding of what has been implemented in the code by me:
https://www.theadarshmehta.in/blog/Extra-Images/Hospital%20Management%20Program%20Idea.jpg
I am pretty sure that now you can make progress on your own and do not require any further help of mine. But feel free to contact me in case you face any serious errors or have any major doubts.
Thank you.
Got your email.
I am glad you found my draft code on Hospital Management Java program useful!
Thank you.
Write a code in Java.
There is an India-Pakistan ODI cricket match happening next month! BCCI has received 200 tv ads from companies to be shown during the match. The ads are of variable lengths between 10s and 59s. The total duration of ads to be shown in the match is 120 minutes.
Please help me, anybody knows this code?
Sounds like an interesting topic Arjun.
I did not fully understand what you have tried to explain, but from what I understood, I think, you will have to use arrays. Sounds not very complicated and you should be able to do it all by yourself if you have a proper understanding of arrays and other basic Java functions.
It is a time-consuming topic though and I do not have enough time right now brother. So I would not be able to help you out in any way. Hope you understand.
I really wish someone else reads your comment and decides to help you out.
Thank you.
You can use null loops for the ads.
Like I have one for you:
This gives a pause of 22 secs (roughly).
You can now play up with the values of ‘crs’ and ‘cs’ and time it.
Although I don’t think you would need, you can use ‘n’ number of nested loops…
Hope this was a help…
Thanks.
Brilliant idea Soumyaa!
I remember now that during my school days, our teacher gave us this idea so that we could use it for time-related programs in our projects.
I had totally forgotten about it but thanks to you, my mind has been refreshed.
Thank you.
My pleasure sir…
Can you help me…???
Can you please send me the sample program in hospital management system…???
Hello, Elina.
Earlier, I had sent Ansh a semi-complete draft code about hospital management system and also an image showing what I have done in that code, via email.
I have sent the same to you via email. Please revert back when you find the same.
Thank you.
Can you please give me some ideas for a project, please!!!
I beg of you…
Though, I know how to do it, I’m black about ideas…
Please help me out Adarsh Mehta.
Hello, Pranathi.
I am quite appalled that you are not able to think of any good idea for your Java project. I am pretty sure if you surf the internet and spent an hour or two, you will be able to find a great topic for your Java project all by yourself.
Nevertheless, here are some of the Java project topics (for ICSE 10th standard students) that I could think of after reading your comment:
These are all the topics I can think of right now. I would urge you not to get annoyed over the fact that you are not able to think of an amazing unique topic for your Java project. Get over it. It is not compulsory to choose a unique topic. I hope you understand.
Thank you.
Hello Adarsh Sir,
Can we do player vs player in hand cricket project in Java?
Yes, Ayush, you most certainly can!
It is fairly simple to implement player vs. player in my code.
You just have to remove the parts of the code where a random number is generated and is displayed on the screen saying, “Computer’s Number”. In place of that, put a readLine function and assign a new variable which reads what integer the second player types. And of course, you have to make some other small adjustments accordingly.
I hope you understood what I tried to explain.
And by the way, player vs. player makes no sense because both the players will have to sit in front of the computer, so they both will be able to watch what the other player is typing! You will either have to make them turn on their backs every time the other player types or believe in their honesty, LOL.
And as always, if you face any problems in implementing it, feel free to reply back!
Thank you.
Sir, please make a program on restaurant including arrays. It would be a great help to get ideas from your great programming skills. I hope you will reply soon.
Brother Rajiv, I would love to help you out, but I do not have enough time. I have my IPCC exams coming soon for which I have to prepare. Also, I have many other routine works because of which, I won’t be able to devote much time to writing a code specially for you.
Here is a rough idea, though:
I hope you got a rough idea. Now, you should be able to write the code on your own. If you are not able to write it on your own, you must not be good at coding, in which case, stick to an easy project topic. It is not necessary that you make a complicated and hard project. Just make something which you completely understand and you will do just fine.
And of course, if you need any help or have any doubts, feel free to contact me through the contact form or through my email id. But I probably won’t be able to reply within a reasonable time period as I am busy for the following 2 months.
Thank you.
Thank you.
HELLO ADARSH SIR, I AM DESIGNING HAND CRICKET GAME PROGRAM WITH MY DIFFERENT LOGIC. IF YOU DONT MIND, CAN I SHARE MY PROGRAM WITH YOU? AS I AM MODIFYING IT. YOU SUGGESTED ME 7 TOPICS, BUT I DIDN’T GET THE 4TH TOPIC. CAN YOU EXPLAIN ME THAT TOPIC AGAIN?
THANK YOU.
OKAY, FIRST THINGS FIRST. YOU DO NOT NEED TO TYPE LIKE THIS.
Now Mithilesh, you can do whatever you like with this code. It has been made available to the public by me without any restrictions. And feel free to share your modified version with me through the contact form on this blog or my email id.
Also, I am sorry to have explained the 4th point so badly. It basically means accepting a word from a user, say ‘Ell’, and displaying it like this maybe:
___
|__
|___
|
|___
|
|___
There are endless possibilities, but you get the idea, right?
You can visit the following links to get some more information and examples regarding this type of ASCII Art:
http://www.network-science.de/ascii/
http://patorjk.com/software/taag/
http://www.kammerl.de/ascii/AsciiSignature.php
Looking forward to hearing from you soon.
Thank you.
HELLO ADARSH SIR, I AM IN GRADE 10 AND I HAVE TO DESIGN A GAME. CAN YOU SUGGEST ME A FEW IDEAS?
Sure, Mithilesh.
Here are some of the few topics you can base your projects on:
Finally, I would like to add that please do not think a lot about your topic. They do not give a lot of importance to your program code at this stage. So just make something nice and unique. Have a fine understanding of your work and you will do just fine!
Thank you.
hello adarsh dude, i have atlast scored a century on the hand cricket thanks for this awesome game man.please create more interactive games like this
Sir can you make a code on ‘hospital management’, which accepts details of patients, diseases etc. I am in 10th and I don’t have any idea about my project.
Dear Ansh, I surely CAN make a program on Hospital Management, but I won’t. Because even you should be able to do that if you have a proper understanding of Java programming.
And it would not be nice of me to make a project just so that you can get marks. That will not make you learn and explore new things in Java programming.
Please understand that it is not necessary to make an amazing project to get full marks. Just make something simple and unique and perfect and have a full understanding of it. The examiner will grant you perfect marks if you do so.
I hope you understand and I wish you All the Best of Luck in all your endeavours.
Thank you.
Sir could you please make a draft code for me to work on?
And once I modify that code, I’ll send it to you first.
I have done what you asked of me. Please check your email. I have sent you a semi-complete draft code and also an image showing you what I have done in the code. I hope you are satisfied.
Thank you.
Hi Sir,
I loved your creation, but sir, can I ask for your help for making the program better, adding something like array? Or to play for ten people which make the program look better.
For eg :-
Sachin 10 Runs
Rahul 100 Runs
Etc.
And even for different number of players each side!
I am a student of Grade 10 and I am given a project to make a game and I loved your program.
I need to submit it on 5 September.
Please help sir.
Thanks.
Hello Mohak.
I am glad that you liked my creation.
I like your idea of making this program better by introducing the option for multiple players to play the game. It can be implemented easily. Sadly, I am not fluent with Java programming language right now as it has been two-three years since I last used it. Also, it would make the program code very lengthy and complicated to normal people. Because of these two reasons, I am not gonna be spending any time on implementing your idea and turning it into a creation.
I would also like you to know that I had submitted my project (three years ago) consisting of just this Hand Cricket game and a Quiz game (two games in one project) and I got full marks in my project. A lot of my friends did. You just need to have a perfect unique project, have a full understanding of each and every line of your code, answer the questions they ask properly with confidence, and you will be awarded proper marks. You do not need to worry.
Sorry for replying so late, but if you want, you can still apply the changes you suggested in your project within a span of few hours, all by yourself, and submit your project. Although, I doubt they would even notice your program. In my experience, they will not lay much focus on how great your project is because they have plenty of other students to attend to!
Thank you.
The output is not coming sir, please help me!
I am sorry to hear that Taranum. Could you please explain to me what is the error that is being displayed? And which compiler are you using? Please tell me all the details about your problem and I will be happy to help you out.
Also, I have pasted the java program code on this link as well, just in case you had any trouble copying it from my blog:
http://pastebin.com/J4UJmeLT
I would urge you to copy that code properly, create a new class in your project (in whatever compiler you are using, preferably BlueJ) and then paste the copied code and then compile it. It should not show any errors. But still, if it does, do not hesitate to contact me.
Thank you.
This is no syntax error but I’m unable to play.
We have to go to string for the output, right?
But I am unable to do so. Can you please help me?
I am not able to clearly understand what you are trying to say Taranum. But since you are so desperate for help, I have uploaded a video of me compiling and running the program in BlueJ from scratch.
Please open this link and watch the video:
https://youtu.be/WZT4b0wJ5co
Let me know if you still face any issues. I doubt that will happen, though!
Thank you.
DUDE, LOVE YOUR RANDOM SHIT (STUFF U MAKE)!!!!
Really glad someone loves my work. If you want, I can make more!
Thank you.
I want hand Cricket but only runs including 1 to 6
Abhimannyu, you can use the following piece of code to generate a random number (natural number only) between 1 and 6 (both inclusive):
Thank you.
What is the use of this program?
I appreciate you taking the time to read this post, Minakshi.
Thank you.