Professional Documents
Culture Documents
JAVA Microroject
JAVA Microroject
ASTUDY ON
MICRO PROJECT
Submitted by 4 students
PROF.MS.TAMANNA SHAIKH
in
Three Years Diploma in Engineering & Technology of Maharashtra State Board of Technical
Education, Mumbai (Autonomous)
SO 9001:2008 (ISO/IEC-27001:2013)
At
Certificate
Sr No. Title
1. Introduction
2. Abstract
3. Information
4. Code
5. Conclusion
6. Reference
INTRODUCTION
A Guessing Game is a game where the computer will choose any random
number between 1 and 100, and you have to guess that number. Every time you
choose a number, the computer will tell you whether your guess is right or
wrong than the number selected by the computer. Well, keep in mind that you
Trinity Polytechnic Pune
only get three tries to guess the number. At the end of the game, it will tell you
what number was chosen by the computer (if you are unable to guess the correct
number). And, if you choose the correct number, then it tells you how many
tries it took you to guess the number
Computer Department 4
Trinity Polytechnic Pune
ABSTRACT
About Project
If the guessed number is more than the real number, the program will
display the message "guessed number greater than the actual number."
If the guessed number is less than the real number, the program will
display a message indicating that the guessed number is less than the
actual number.
If the guessed number is the same as the real number, or if all K trials
have been completed, the program will terminate with an appropriate
message.
Computer Department 5
Trinity Polytechnic Pune
INFORMATION
Random Numbers
Random numbers are the numbers that use a large set of numbers and select a single number
from them using a mathematical algorithm. It satisfies the following two conditions :
Dice Roller
Scientific Hypothesis
Statistics
Random number series, and many more.
The Java Math class contains numerous methods for performing various mathematical
computations. The random() method is one of them. It belongs to the Math class and is a
static method. As you may know, in Java, static methods are methods that can be called
without first generating a class instance.
So, the random function being a static method, can be called directly. Only double data type
random numbers will be generated, and the generated number can be larger than or equal to
0.0 and less than 1.0 are generated. We must first import the java.lang.Math class before we
can use the random() method, or else the compiler will throw an error.
Computer Department 6
Trinity Polytechnic Pune
Control statements
Control Statements are the base of any programming language. Using control
statements we implement real world scenarios in programs. There are three
types of Control Statements in Java:
Decision-Making Statements
Loop Statements
Jump or Branch Statements
Decision-Making Statements
1. If Statement
These are the simplest and yet most widely used control statements in Java. The
if statement is used to decide whether a particular block of code will be
executed or not based on a certain condition.
Computer Department 7
Trinity Polytechnic Pune
2. if-else Statement
That's where else statement is used. In this, if the condition is true then the code
inside the if block is executed otherwise the else block is executed.
Let's see the execution flow of the if-else statement in a flow diagram:
Computer Department 8
Trinity Polytechnic Pune
Loop Statements
1. while Loop
The while loop statement is the simplest kind of loop statement. It is used to
iterate over a single statement or a block of statements until the specified
boolean condition is false.
The while loop statement is also called the entry-control looping statement
because the condition is checked prior to the execution of the statement and as
soon as the boolean condition becomes false, the loop automatically stops.
You can use a while loop statement if the number of iterations is not fixed.
Normally the while loop statement contains an update section where the
variables, which are involved in while loop condition, are updated.
Let's see the execution flow of the while loop statement in a flow diagram:
Computer Department 9
Trinity Polytechnic Pune
2. for Loop
Unlike the while loop control statements in Java, a for loop statement consists of the
initialization of a variable, a condition, and an increment/decrement value, all in one line. It
executes the body of the loop until the condition is false.
The for loop statement is shorter and provides an easy way to debug structure in Java. You
can use the for loop statement if the number of iterations is known.
In a for loop statement, execution begins with the initialization of the looping variable, then it
executes the condition, and then it increments or decrements the looping variable.
If the condition results in true then the loop body is executed otherwise the for loop statement
is terminated.
Let's see the execution flow of the for loop statement in a flow diagram:
Computer Department 10
Trinity Polytechnic Pune
CODE
import java.util.Scanner;
import java.util.Random;
int numRandom=generator.nextInt(100)+1;
return numRandom;
//Variable Declaration//
int numRandom;
int numGuess1;
int numGuess2;
int numGuess3;
Computer Department 11
Trinity Polytechnic Pune
int reply=0;
//Scanner object//
//Main Program//
System.out.println(greeting1);
System.out.println(" ");
System.out.println(greeting2);
System.out.println(" ");
System.out.println(prompt1);System.out.println(choice1);System.out.println(cho
ice2);
reply = keyboard.nextInt();
while (reply==1)
Computer Department 12
Trinity Polytechnic Pune
System.out.print(prompt2);
numGuess1=keyboard.nextInt();
System.out.println(" ");System.out.print(second);
numGuess2=keyboard.nextInt();
System.out.println(" ");System.out.print(last);
numGuess3=keyboard.nextInt();
if (numGuess1==numRandom||numGuess2==numRandom||numGuess3==numRandom)
//if loop1//
System.out.println(" ");
System.out.println(display1);
System.out.println(" ");
else
System.out.println(" ");
System.out.println(display2);
System.out.println(" ");
System.out.println(display3+numRandom+" ");
System.out.println(" ");
System.out.println(prompt3);
System.out.println(choice1);
System.out.println(choice2);
reply=keyboard.nextInt();
Computer Department 13
Trinity Polytechnic Pune
if (reply==2)
System.out.println(goodbye2);
while (reply==2)
for(;reply>=2;reply--)
System.out.println(goodbye1);
Computer Department 14
Trinity Polytechnic Pune
PROGRAM OUTPUT
Computer Department 15
Trinity Polytechnic Pune
Computer Department 16
Trinity Polytechnic Pune
CONCLUSION
Computer Department 17
Trinity Polytechnic Pune
REFERENCES
https://www.scaler.com/topics/
https://www.scaler.com/topics/math-random-in-java/
https://www.scaler.com/topics/control-statements-in-java/
Computer Department 18