This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Problem with tic tac toe game

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All,

I am a newbie. I have enclosed some code I am working on. It is the beginning of a tic tac toe game. When I enter two different names, the program only reports the second entered name as both players. What in the frig am I missing?? Thanks for any insight.

David C







 
Ranch Hand
Posts: 235
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at lines 5 and 22 in the Player class.You have two players but only one place to store the name.

I'd probably go about things a little differently, but it runs and you don't fix what a'int broke.

Regards,
Robert
 
D Chandler
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Robert,

Thanks for the reply. I would be curious to see your "I'd probably go about things differently." As a newbie, I am always curious to see ways that may be more common, efficient, more generally accepted, and etc. If it is not too much trouble, would you mind offering your suggestion?

Thanks,

David C
 
Bartender
Posts: 708
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The playerNum and name fields of class Player should be instance variables, not static (class) variables.
 
lowercase baba
Posts: 12754
51
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Robert D. Smith wrote:, but it runs and you don't fix what a'int broke.


Today's XKCD has a great quote about "well, it runs fine for now":

"So does a burning bus"
 
Marshal
Posts: 67275
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Fred Kleinschmidt wrote:The playerNum and name fields of class Player should be instance variables, not static (class) variables.



As should the methods.

And I would argue that this is very much broke. "Running" is not the same a "not broken".

My rule for novices using "static" is "don't"*


* Except for main, of course
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!