You are on page 1of 9

Government Polytechnic ,Washim

Maharashtra State Board Of Technical Education,Mumbai


Washim,Maharashtra 444505

A Project Report On

“ Guessing game ”

Guided By :-
Prof. M.S.Hule

Submitted By :-

Sr no Name Enrolment No Roll umber


1 Vedant Pingalkar 2000310244 45

2 Krushna Dhore 2100310280 63

3 Tushar Bhagat 2100310278 61

4 Shubham Thakre 2100310285 68


Sr no Name Enrollment No Roll
number

1 Vedant Pingalkar 2000310244 45

2 Krushna Dhore 2100310280 63

3 Tushar Bhagat 2100310278 61

4 Shubham Thakre 2100310285 68

A report has been approved as it satisfies the academic


requirements in respect of a project work prescribed for the course

………………………
Prof. M.S.Hule
Index

content Page no
Sr no

1 ACKNOWLEDGEMEN 1
T

2 Introduction 2-3

3 Source code 4

4 output 5

5 Refrences 6
ACKNOWLEDGEMENT

We would like to express my gratitude to all the people


behind the screen who helped me to transform an idea into a
real application. We profoundly thank Prof. Dr.
B.G.Gawalwad principal of our institute who has been an
excellent guide and also a great source of inspiration to our
work. We would like to thank our Professors of Information
Technology branch for his technical guidance, constant
encouragement and support in carrying out my project at
college.

The satisfaction and euphoria that accompany the


successful completion of the task would be great but
incomplete without the mention of the people who made it
possible with their constant guidance and encouragement
crowns all the efforts with success. In this context, We would
like thank all the other staff members, both teaching and non-
teaching, who have extended their timely help and eased our
task.
Introduction

The fun and easy project “Guess the


Number” is a short Java project that
allows the user to guess the number
generated by the computer & involves the
following steps:

1.The system generates a random number from


a given range, say 1 to 100.

2.The user is prompted to enter their given


number in a displayed dialogue box.

3.The computer then tells if the entered number


matches the guesses number or it is
higher/lower than the generated number.

4.The game continues under the user guessing


the number.
You can also incorporate further details
as:

 Limiting the number of attempts.

 Adding more rounds.

 Displaying score.

 Giving points based on the number of attempts.


Source code :-
package guessinggame;

/* Java game Guess a Number that allows user to guess a random number that has
been generated.
*/
import javax.swing.*;
 
public class Guessinggame {
    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;
        }
    }
Output:-
References:-
www.wikipedia.com
www.interviewbit.com
www.tutorialpoint .com
chrome and various google sites

You might also like