• 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
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

help in tic tac toe program  RSS feed

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in the attached file

i have problem with the percentage_games and percentage_games1 variable
it is not updating correctly as when both X and O have 1won 1 game each it should show percentage as 50 but it is showing 100 and 0

please help!!

my program is as follows:



 
Bartender
Posts: 825
5
Java Python Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Keep in mind that the division operator denotes integer division if both operands are integers, and floating-point division otherwise. Yours is the first case - both of your operands are integers (e.g. 1/2 = 0 by integer division), hence the results you get.
 
Saloon Keeper
Posts: 3252
128
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check your lines 265 and 266. It has to do with integer division.

Greetings,
Piet
 
ten doeschate
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can yu help me how to use showStatus() in above program by extending JApplet

it is showing error as NullPointer Exception

please help
 
Piet Souris
Saloon Keeper
Posts: 3252
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't find a "showStatus()" method in your code.

And, is it your intention to run "TicTacToe" as an applet?

A remark: you are using expressions like "if (letter == "X") {...}".
Since you are using string literals here, you might get away with this. But you should always use "if (letter.equals(someOtherString)) {...}".
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!