Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with chessboard location method  RSS feed

 
Greenhorn
Posts: 7
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm writing a location method for a chess board, my approach:



When I create an object of the class, such as Location loc = new Location ("d8") and then print the location, it is always (0,0). (Shouldn't be, d8 would be 0,3)

Any ideas? Thanks for reading and thanks in advance for advice/help.
 
Saloon Keeper
Posts: 8910
167
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah. Never use == for value comparison. St‌ring is a reference type, so == compares references, not values.

Anyway, you can do this without looping through arrays. char is an integral type that you can perform arithmetic on. All you need is String.charAt() and some maths.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!