wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Guess the Number Game Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Guess the Number Game" Watch "Guess the Number Game" New topic
Author

Guess the Number Game

natsumi jay
Greenhorn

Joined: May 02, 2013
Posts: 8
Hi! I'm making a Guess the number game where the user guesses what number the random generator chose.
However, I want to make it so that there are 2 classes. One with the methods and the other where it has the while loop and actually calls upon the methods.
But I'm not too sure on how to go about actually writing it and choosing what methods to write.
Any help would be appreciated!
I have this so far:

Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

You might give it a look, there might be much better designs though, this is my idea.



Swastik
natsumi jay
Greenhorn

Joined: May 02, 2013
Posts: 8
Hi! I was wondering what this line did.


And thank you for the response! Some of it went over my head but I think I have the general concept to write the classes/use them.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

You are most welcome. As far as your query is concerned, you should read about ternary operator. The following code



is same as

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

And it's also equivalent to this:



In general it isn't worth using the ternary operator when a plain old boolean will do.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
Please also learn about spaces and use of the _(←link) character. Your code without spaces and with _ is very difficult to read.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7552
    
  18

Campbell Ritchie wrote:Please also learn about spaces and use of the _(←link) character. Your code without spaces and with _ is very difficult to read.

@natsumi: Also, the use of the '_' prefix in field names marks you out as an "immigrant" from languages like C/C++, Python or Perl, where it has a specific meaning (not necessarily the same either, depending on which language you're coming from, AFAIK).

My advice: Don't use it. It looks 'awkward' to most Java programmers.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
wood burning stoves
 
subject: Guess the Number Game
 
Similar Threads
Java Guessing Game
Unable to Return Variable
Play again function help?
Need help ending number guessing game and asking if user wants to play again
Limiting time for user response