Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create an object and use it with the number guessing game in Java. I am just about done with this assignment, however, I need to

Create an object and use it with the number guessing game in Java.

I am just about done with this assignment, however, I need to use an object to count the number of tries it takes the user and for some reason it keeps it at 1 instead of increasing. Here is my code so far.

Main Class:

image text in transcribed

NumberGame class:

image text in transcribed

ch04 ex4_GuessingGame - NetBeans IDE 8.2 File Edit View Navigate Source Refactor Run Debug Profile Team Tools Window Help | Projects X -Start Page x|ES9Mainjava x st NumberGamejava x ch04_ex4_GuessingGame Source Packages ?.fi package murach.games: murachgames Main.java NumberGame.java import java.util.Random; import java.util.Scanner; Libraries 5 public class Main public static void main (String args[]) i System.out.println("Welcome to the Number Guessing Game") System.out.println ); 10 Scanner sc new Scanner (System. in); int upperLimit -50 // Get upper limit removed System.out.print ("The upper limit is:" upperLimit "In") NumberGame object new NumberGame (upperLimit) System.out.println("OK, I'm thinking of a number between 0 and "+ 12 13 14 15 16 17 18 19 20 21 object.getUpperLimit )) System.out.println ) // Generate a random number between O and the upperLimit variable Random random - new Random ); int number = randon.nextInt(upperLimit - 1) + 1; 23 24 25 26 27 28 29 30 31 32 int count 1; System.out.print ("Enter your guess: "); int guessInteger.parseInt (sc.nextLine )); while (guess !- number) object.incrementGuessCount ) if (guessnumber) System.out.println ("Your guess is too high.In") 35 36 System.out.print ("Enter your guess: "); guessInteger.parseInt (sc.nextLine ()) System.out.println ("Correct!n") System.out.println("You gessed the correct number in"+ count + System.out.println("Bye!"): 38 39 "guesses. "); & > ? main ? Output ch04_ex4 GuessingGame (run) X Your guess is too high murach.games.Main Type here to search

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions

Question

Appreciate the importance of new-employee orientation

Answered: 1 week ago

Question

=+ What topics are contained in the contracts?

Answered: 1 week ago

Question

=+Are they specific or general in nature?

Answered: 1 week ago