Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Guess the Number Game

 
natsumi jay
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might give it a look, there might be much better designs though, this is my idea.

 
natsumi jay
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21137
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49437
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10427
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic