Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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: 732
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: 12855
52
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"
 
Sheriff
Posts: 67399
173
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
 
We can walk to school together. And we can both read this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic