Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
11 views4 pages

Java Group 2-WPS Office

The document describes a Java course project focused on creating a guessing game. It includes a list of students enrolled in the course and provides the Java code for the game, which allows users to guess a randomly generated number with a maximum of five attempts. The output section illustrates the game's interaction with the user, including prompts and feedback based on the user's guesses.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Java Group 2-WPS Office

The document describes a Java course project focused on creating a guessing game. It includes a list of students enrolled in the course and provides the Java code for the game, which allows users to guess a randomly generated number with a maximum of five attempts. The output section illustrates the game's interaction with the user, including prompts and feedback based on the user's guesses.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Java Group 2

Course: Java

Code: Com 106

Topic: A Guessing Game Using Java

Lecturer: Engr Toxin

Oladehinde 032210002 Computer science


Olajuwon Ibidapo

Olawale Habbeeb 032210163 Computer science

John Promise 012210171 Law

Adulewa Stephen 032210066 Computer engineering

Orowale Timileyin 012210128 Law

Olaniyi David 012210140 Law

Adedeji David 012210033 Law

Obam Salome 032210005 Computer science

Uzoma Victor 032210112 Computer Science

Abbah Benjamin 032210009 Computer science

Idowu Abraham Computer science

Omoare Ayomide 032210111 Computer Science

Oluwafemi Enoch 032210076 Computer Science

CODE BELOW:

import java.util.Scanner;

public class Game


{

public static void main(String args[])

int attempt = 1;

int userGuessNumber = 2;

int secretNumber = (int) (Math.random() * 99 + 1);

Scanner userInput = new Scanner(System.in);

System.out.println("Dear value user ");

System.out.println("Welcome to Guess Number Game \nYou Will Be Asked To Guess A


Number To Win The Game \nYou have Maximum 5 Attemp Limit");

do {

System.out.print("Enter a guess number between 1 to 100\n");

if(userInput.hasNextInt()) {

userGuessNumber = userInput.nextInt();

if (userGuessNumber == secretNumber)

System.out.println("OOhhOO!, Your Number is Correct. You Win


the Game!");

break;

else if (userGuessNumber < secretNumber)

System.out.println("Your Guess Number is Smaller.");

else if (userGuessNumber > secretNumber)

System.out.println("Your Guess Number is Greater.");

if(attempt == 5) {
System.out.println("You have exceeded the maximum attempt.
Try Again");

break;

attempt++;

}else {

System.out.println("Enter a Valid Integer Number");

break;

} while (userGuessNumber != secretNumber);

Output Below:

Dear value user

Welcome to Guess Number Game


You wlll be asked to guess a number

You have max. 5 attemp limit

Enter a guess number between 1 to 100

Enter a valid int. Number

You are close to the number and your number is high that the guess number

You are far to the number and your number is high that the guess number

Ohooh you won

You get it right

Press 1 to continue

Press 2 to quit

You might also like