aspose file tools*
The moose likes Java in General and the fly likes Method not working or operating in program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Method not working or operating in program" Watch "Method not working or operating in program" New topic
Author

Method not working or operating in program

Sam Thompson
Ranch Hand

Joined: Jul 05, 2011
Posts: 93
    
    1
Hi everyone

As of right now I am writing a program that will allow me to store data from an event (you will see it is by looking at the code) ino a file.

However, I am having trouble with certain parts of the program. Here is the code below for perusal. In order to help you find and pinpoint the problem, I have posted t0he program along with the Exception class and other class along with it after this posting. I tried to attach them to the Forum but it won't let anything with the .java extension to be uploaded and attached.

What I am having difficulty in particular with is the gameState() method. How I know it isn't working is because it is supposed to ask you for more input as soon as it is called, but it doesn't. It seems as if the main() method just skips it and moves on.

Is there anything I am doing wrong here?

What do I need to do for the gameState() method to be called and run properly?

Whatever help you can provide would be greatly appreciated.

Thank you in advance everyone.

Hope to hear from you soon.

S.T.

PS: If it helps make things easier the gameState() method is on lins 106 - 185 in PokerGenerator and where it is called, is line 230, PokerGenerator also. Thank you so much in advance.
Sam Thompson
Ranch Hand

Joined: Jul 05, 2011
Posts: 93
    
    1
Poker Player class

Sam Thompson
Ranch Hand

Joined: Jul 05, 2011
Posts: 93
    
    1
Main() method

Sam Thompson
Ranch Hand

Joined: Jul 05, 2011
Posts: 93
    
    1
Exception class

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Please check about naming conventions; you should only use _ in package names or CONSTANT_NAMES in upper‑case.
Several of your methods should be tidied up. For example this:-…appears to do two things. It alters the pot and returns it. A method should do one thing. So this method should have a void return type and should simply alter the amount of the pot. If you need access to the pot amount, use a getPot method.
Never use == true, which is error‑prone. Not if (b == true)... nor if (b == false)..., but if (b)... and if (!b)... The versions without the ! are to be encouraged if possible as being easier to read.
You appear to be throwing an Exception and catching it in the same method. That is simply a very inefficient way of executing an if (...)...else..., so you should replace it with an if-else. Your Exception class appears to have a new method. Why? You should probably delete that method and simply give that class constructors and use methods inherited from Exception.
Also get rid of those if (...)b = true; else b = false; blocks.
Maybe you should get the user to enter true or false and use nextBoolean(); then your loop will continue only on true (or TRUE, etc) in line 242.
that main method is much much too long. The ideal length for a main method is one line. You should move 99% of that code out of it into other methods.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

Sam

Given that the gameState() method contains a lengthy for loop, I would debug your program and confirm what values are being passed into this method. It is likely that the loop is not being executed at all.

I second what Campbell says btw. You should read up on standard Java conventions for naming methods, variables etc.
Sam Thompson
Ranch Hand

Joined: Jul 05, 2011
Posts: 93
    
    1
Campbell and James:

Thanks for the tips. I do have to brush up on some things I have to admit.

James:

How would I confirm what values are and are not being passed into the gameState() method exactly? Heck, it asks for user input as soon as the for loop starts. To be perfectly honest, I have been having problems with coding this process for the past two weeks and so far this is the closest and best thing I have come up with so far?

What I want to do is to have the user manually enter poker game data into the program to be stored into a .csv or .txt file for later use. However, the conundrum that I have been confounded with is how exactly do you account or program or tell or whatever the computer when players are consecutively raising. That is why I have the do-while loop IN the for loop.

Like example if you have Moe, Larry, Curly and Shemp play poker, and Moe decides to raise by $a. How exactly do you tell the computer if Larry raises after Moe by $b, then Curly by $c? Players could keep raising until FINALLY someone calls and ends the process.

Do you have any suggestions. Code examples would be of great help.

Thank you so much for the input and for the future input I hope to get from you (and anyone else daring enough to tackle this challenge with me haha.)

S.T.
Stuart A. Burkett
Ranch Hand

Joined: May 30, 2012
Posts: 679
Sam Thompson wrote:How would I confirm what values are and are not being passed into the gameState() method exactly?

Add these two lines (plus ones to print out any other values you think might be useful) before the loop

Sam Thompson
Ranch Hand

Joined: Jul 05, 2011
Posts: 93
    
    1
I got that now ... and I managed to find the solutions to some problems.

But the for loop still isn't working. Where am I going wrong? I want the program to start at the player the user says.

S.T.
Stuart A. Burkett
Ranch Hand

Joined: May 30, 2012
Posts: 679
Sam Thompson wrote:But the for loop still isn't working.

In what way is it 'not working' ?
If it never enters the for loop then the values I suggested you print should tell you why. Once you've worked that out, you will need to either change the values you are passing to the method or change the for loop initialisation and/or condition check.
If it is entering the for loop but not doing what you expect, then you need to tell TellTheDetails.
 
wood burning stoves
 
subject: Method not working or operating in program