You are on page 1of 14

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

SIDDHANT COLLAGE OF EMGINEERING


A/P Sudumbare Tal-Mavel Dist-pune

Micro Project
Academic Year (2021-22)
Maharashtra State Board of Technical Education
Program code and name: CO
Subject: Programming in java
A Micro Project on
Guss Number Game
Sr. Roll No. Student Name Enrollment No. Seat No.
1 Yash Botre 2016240019
2 Om Markad 2016240017

Under Guidance of
Ms. Kajal Gade Mam …
Maharashtra State Board of Technical Education

Certificate
This is to certify that Mr. Yash Botre……. Roll No….. Of fourth
Semester of Diploma in Computer Engineering of Institute, Siddhant
college of Engineering (Code: 1624) has completed the Practical
Activities (PA) satisfactorily in Course java Programming (code:
22412) for the academic year 2021 – 2022 as prescribed in the
curriculum.

Place: Sudumbare Enrollment No: 2016240020


Exam. Seat No: …………………………

Subject Teacher Head of Department Principle


Maharashtra State Board of Technical Education

Certificate
This is to certify that Mr. Om Markad……. Roll No….. Of fourth
Semester of Diploma in Computer Engineering of Institute, Siddhant
college of Engineering (Code: 1624) has completed the Practical
Activities (PA) satisfactorily in Course java programming (code:
22412) for the academic year 2021 – 2022 as prescribed in the
curriculum.

Place: Sudumbare Enrollment No: 2016240017


Exam. Seat No: …………………………

Subject Teacher Head of Department Principle


ACKNOWLEDGEMENT
It is a matter of great pleasure by getting the opportunity of
highlighting. A fraction of knowledge I acquired during our
technical education through this project.

This would not have been possible without the guidance and
help of many people. This is the only page where we have the
opportunity of expressing our emotions and gratitude from the
core of our heart to them. This project would not have been
successful without enlightened ideas, timely suggestions and
interest of our most respected guide Of Ms. Kajal Gade mam
without her best guidance; this would have been an impossible
task to complete.

I would like to thank Mrs. Sarita Kale mam Head of our


department for providing the necessary facility using the period
of working on this project work. I would also like to thank our
Principal Mrs. Nanda Kulkarni mam who encouraged us and
created a healthy environment for all of us to learn in the best
possible way.

Finally, I would pay my respect and love to my parents and all


Family members as well as friends for their love and
encouragement throughout this Micro Project.
Index
Sr. No. Content
1 Abstract
2 Introduction
3 Source Code
4 Out Put

5 Conclusion
6 Reference
Abstract
This Guess the number game can be played easily and need
only one player because on the other end there will be a
computer playing with you.
Random () method is used to pick a random number. Random
number extent (100); here 100 denotes that the random number
range will be bounded by 100.
int turn is initialized to zero so that it can count the number of
turns user has used to guess the right answer. For each iteration,
the value of turn will be increased by 1 as we put turn++ in our
loop.
Introduction
I will be sharing the number guessing game in java with source
code. As the name suggests, the player needs to guess the
number between two given numbers.

This game is played between more players

In this number guessing game, the computer will pick the


SECRET number and the player who should find this SECRET
number within a given number of tries. Let's understand the
rules of the game first before moving on to the algorithm and
java program. 1. The computer randomly selects the SECRET
number within the defined range of numbers, here 1 to 100,
and prompts the player to guess the number.

2. In this program, we ask the player to enter any number


between 1 to 100. The player enters any random number
within the defined range. We call it as inputNumber.

3. If the player number i.e inputNumber is same as the


SECRET number then the game stops, otherwise,
Source Code

import javax.swing.*;

public class aa
{
public static void main(String[] args)
{
int computerNumber = (int) (Math.random()*100
+ 1); int userAnswer = 0;
System.out.println("The correct guess would be " +
computerNumber); int count = 1;

while (userAnswer != computerNumber)


{
String response =
JOptionPane.showInputDialog(null, "Enter a
guess between 1 and 100", "Guessing Game", 3);
userAnswer = Integer.parseInt(response);
JOptionPane.showMessageDialog(null, ""+
determineGuess(userAnswer, computerNumber, count));
count++;
}
}

public static String determineGuess(int userAnswer, int


computerNumber, int count){ if (userAnswer <=0 || userAnswer >100)
{ return "Your guess is invalid";
}
else if (userAnswer == computerNumber ){
return "Correct!\nTotal Guesses: " + count;
}
else if (userAnswer > computerNumber) {
return "Your guess is too high, try again.\nTry Number: " + count;
}
else if (userAnswer < computerNumber) {
return "Your guess is too low, try again.\nTry Number: " + count;
} else
{
return "Your guess is incorrect\nTry Number: " + count;
}
}

}
Out Put
Conclusion

If the guessed number is bigger than the actual number, the


program will respond with the message that the guessed number
is higher than the actual number.

If the guessed number is smaller than the actual number, the


program will respond with the message that the guessed number
is lower than the actual number.

If the guessed number is equal to the actual number or if the K


trials are exhausted, the program will end with a suitable
message. to generate a random number using Math.random()
method in Java.

Now using a loop, take K input from the user and for each input
print whether the number is smaller or larger than the actual
number.

If within K trials the user guessed the number correctly, print that
the user won.

Else print that he was not able to guess and then print the actual
number.
Reference

 www.google.com
 www.w3schools.com
 www.codecamp.org
 www.programmingboss.com

You might also like