Results 1 to 8 of 8
  1. #1
    VettesRus is offline Member
    Join Date
    Jun 2012
    Posts
    35
    Rep Power
    0

    Default Java Program Help

    Delete me please. I appreciate everyones help, but I found out today my teacher said we cannot go on forums for help.
    Last edited by VettesRus; 06-12-2012 at 10:20 PM. Reason: code tags added

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Help with Program...Stone Game

    Hi VettesRus, welcome to the forums!

    When you post code, use the "code" tags: you put [code] at the start of the code and [/code] at the end. It also improves readability to use (a few) spaces to indent rather than tabs which can end up uncomfortably large when rendered on a web page. (For details see the bbcode faq.)

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Help with Program...Stone Game

    My problem is when I get back to the top of the loop my variables holding the remaining stones get reset when the user enters their next turn.
    There is no loop in the code you posted.

    -----

    As a matter of design you might consider writing smaller simpler methods. For example a method that performs the computer's turn, another that prompts the user and performs the human's turn. Then the main() method - complete with loop - would only have to put the other methods together. The advantage of such an approach is that by being simpler the individual parts are easier to test and easier to write correctly.

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Help with Program...Stone Game

    Also at javaprogrammingforums.

    Please be forthright when cross posting. Forums are a place of discussion, and everybody deserves to know what else is being said. Bear in mind that some will be put off and unwilling to help if they suspect they might be wasting their time on a question answered elsewhere. And others annoyed by the suspicion that they are being treated as the gullible targets of a fishing expedition. Of course you are probably not intending to treat other forum participants this way: which is why it pays to be forthright.

  5. #5
    VettesRus is offline Member
    Join Date
    Jun 2012
    Posts
    35
    Rep Power
    0

    Default Re: Help with Program...Stone Game

    pbrockway you are on top of things huh lol. I appreciate the help and information though. For some reason I assumed cross posting just meant repeating old topics, I should have looked into it.

    Also thank you for the code edit, I did not realize.

    As far as the loop goes, I had a loop but deleted it right before I posted this because it kept changing the values of remaningStones. I should have left it for everyone to see, but did not plan on asking for help until I erased it. The only loop I can come up will ask the user how many stones they want to take when it is their turn, but when the user inputs the number, my variables adjust to the new stonesTaken. I cannot figure out how to loop it to keep subtracting the new user input without rejuvinating, if that makes any sense.

    When I was running with my loop everything was fine, until the users second turn, then the stonesRemaining would jump back up to a higher value. I know this probably is hard to follow. I should just go to bed and work on it more tomorrow, then give you a better picture of what I have.

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Help with Program...Stone Game

    When you get a chance it *will* help people to see the loop as you have written it: problems and all.

    Just wondering, but do you really need all those variables? Isn't the only important thing the number of stones remaining? And that does change as each play is made.

  7. #7
    VettesRus is offline Member
    Join Date
    Jun 2012
    Posts
    35
    Rep Power
    0

    Default Re: Help with Program...Stone Game

    Quote Originally Posted by pbrockway2 View Post
    When you get a chance it *will* help people to see the loop as you have written it: problems and all.

    Just wondering, but do you really need all those variables? Isn't the only important thing the number of stones remaining? And that does change as each play is made.
    Working on my loop now. But the user and computer can only take half of the stones left at a time so I need some of those variables. I am sure I have some unnecessary ones in there when I was just doing anything to get it to run correctly. If I can get a working loop I can most likely delete the newRemainingStones and even the compStonesTaken

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,120
    Rep Power
    20

    Default Re: Help with Program...Stone Game

    All you need is the number of stones left.
    That's the only thing that needs to be remembered.
    Things like the number taken by either the computer or the player are short-lived variables and so only need to be declared where they are used.
    For example:
    Java Code:
    private void playerTurn() {
        // Some prompt requesting a number of stones from the player.
        int playerStones = <whatever code here, eg Scanner.nextInt()>;
        // Probably need some validating code here
        remainingStones -= playerStones;
    }
    So the playerStones variable is only used inside the method associated with the players turn.
    The computer would be a similar case.
    The value of remainingStones will start at whatever the starting number of stines chosen is.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 8
    Last Post: 07-12-2011, 02:32 PM
  2. trying to write a program for hangman word game
    By durdanto in forum New To Java
    Replies: 1
    Last Post: 02-12-2011, 03:53 AM
  3. Stone, Paper, Scissors game help
    By Harris68 in forum Networking
    Replies: 1
    Last Post: 12-19-2009, 05:33 PM
  4. Replies: 7
    Last Post: 07-21-2009, 03:39 AM
  5. Java Game Program
    By software_dude_2009 in forum New To Java
    Replies: 3
    Last Post: 02-22-2009, 05:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •