• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

random number guessing game

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello i need some assistance with my java program for class. I created a program that generates random numbers,but i also need the user to guess that random number. i don't quite under stand how to do that part. any help?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Can you explain in more detail what you don't understand?

First of all, can you explain in plain English (or for yourself, in your own native language) what steps need to be done? If you have a plan, then you can start thinking in how to write Java code to implement the plan. Class java.util.Scanner is useful for getting input from the user (see the API documentation).
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it helps if you break the problem down into the atomic parts. My first refinement would be to list three the three major things that need to be accomplished

1) generate a random number
2) Get input from the user
3) Compare two numbers

Notice that none of those three things depend on each other in ANY way. It doesn't matter how I got the two numbers...but once I have them, I need to compare them. It doesn't matter what i'm going to DO with the number I get from the user, I just have to get one.

Once you break it down into problems like that, you then focus on solving ONE of them, with no consideration for the others. To solve one of those problems, you may break it down into sub-components. Getting the number from the user may be broken down into:

2a) prompt the user
2b) get input from keyboard
2c) Validate data
2d) if data not valid, have user try again.

Now you focus on solving one of those things. some of these may need to be broken down even further, after which you focus on solving one of those steps...etc.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic