I need help with a project.

The project utilizes the random number generator. What I have to do is get the player to set the min and max numbers of the game, and then a random number must be generated and the user has to guess what the number is. Once the user guesses the number, a box of *'s appears. So say the random number that was guessed was 5, and the amount of guesses the user took to get there was 7. The *'s would form a box that was 5 *'s across and 7 *'s long. At the very end, the program needs to ask if the user would like to replay, and if they answer yes, the same min and max numbers must be kept and the user can play again.

I'm very lost about this program. I know I have to use the Scanner and Random classes, as well as the loops, but I am very lost as to how to start this program, or even write it? It someone could help me write it that would be awesome. Thank you!

Recommended Answers

All 2 Replies


In your example the box should look like this right??


5 columns, 7 rows of *'s.

Start by taking the description you posted and breaking it down into a number of steps you need to accomplish to solve the problem. For example:

1. Get player to set min & max values
2. Generate random number between min & max
3. Get player to make a guess
... etc.

Note that this is a very high level set of steps. So the next thing you need to do is take each step, one at a time, and break it down further. For example:
1.1 Prompt player to enter the min value
1.2 Read the min value the player enters
1.3 Prompt player to enter the max value
1.4 Read the max value the player enters

Repeat this process until you know how to implement a particular step in Java. For example, step 1.1 would be implemented using System.out.println . You probably already know how to do this, so this step doesn't need to be broken down any further.

Maybe you still don't know how to do step 1.2, so break it down more:
1.2.1 Create a Scanner object that reads user input from the keyboard
1.2.2 Create a variable to store the user input
1.2.3 Get the user input using the Scanner object and store it in the variable
... etc.

Using this method, you should be able to focus on one thing at a time, rather than looking at the whole big picture of the assignment and getting overwhelmed.

Once you are able to write some Java code, compile and test what you have so far. It is better to implement a little bit of code and test it, rather than trying to write your whole program before doing any testing. The latter method will probably produce too many errors and you won't know how to fix them. Rather if you test as you go along, you will get fewer errors and (hopefully) you will be able to tell what's going wrong and fix things one at a time. Then when you have something working, move on to the next step with more confidence that what you have already written is working.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.