• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Guess the Number Game

 
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:

 
Bartender
Posts: 2265
20
Android Java ME Eclipse IDE Java
  • 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
Bartender
Posts: 2265
20
Android Java ME Eclipse IDE Java
  • 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

 
Marshal
Posts: 25682
69
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.
 
Marshal
Posts: 69898
278
  • 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.
 
Bartender
Posts: 10777
71
Hibernate Eclipse IDE 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
 
I like tacos! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic