Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

NIM GAME JAVA PRGOGRAMMING.


  • Please log in to reply
4 replies to this topic

#1 helpjav

helpjav

  • Members
  • 7 posts
  • OFFLINE
  •  
  • Local time:09:23 AM

Posted 11 December 2011 - 01:28 PM

I am supposed to


I am suppoed to:
Write a program that allows two people to play Nim. The
program should start by creating four piles of sticks, each
with a number of sticks that varies from 4 to 8. Display
the piles on the screen. The program should then prompt
the first player to remove a number of sticks from a pile.
Once that player has provided valid input, the program
should then adjust the piles and display the new
configuration. This process should continue until one
player has won the game, at which point the computer should
display a congratulatory message to the winner. At the end
of the game, the computer should start a new game if the
users wish to do so. Once the players state that they are
done, the computer should print the games won by each
player.

And this is what i got so far anyone wanna help me finsih it it would be so helpful :)

class Nimgame
{
public static void main (String[]args)
{
playerName();
pilestack();
ChoosePile();
printPileStick();

}
public static void playerName()
{
System.out.print ("P1 Enter your name: ");
char P1 = In.readChar();
System.out.print ("P2 Enter your name: ");
char P2 = In.readChar();
}
public static int pilestack ()
{

System.out.println ( " " );
int a = 1;
for ( a = 1; a<=4; a++)
{
System.out.println (" ");
int pile = (int)(Math.random()* 4 + 4);
System.out.println("pile " + a + " have " + pile + " sticks");
}
return a;
}

public static void ChoosePile()
{
System.out.println(" ");
System.out.println("P1 CHOOSE YOUR PILE");
System.out.println(" ");
int ChoosepileP1 = In.readInt();
System.out.println(" ");
System.out.println ("P1 CHOOSE YOU NUMBER OF STICKS(MAX OF 3)");
System.out.println(" ");
int ChooseStickP1 = In.readInt();
System.out.println(" ");
System.out.println("P2 CHOOSE YOUR PILE");
System.out.println(" ");
int ChoosepileP2 = In.readInt();
System.out.println(" ");
System.out.println ("P2 CHOOSE YOU NUMBER OF STICKS (MAX OF 3)");
System.out.println(" ");
int ChooseStickP2 = In.readInt();
System.out.println(" ");
}

}



Can you please help

BC AdBot (Login to Remove)

 


#2 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:07:23 AM

Posted 11 December 2011 - 01:42 PM

We are not going to just do your work for you. If you have a specific programming question we'll be happy to help, but you can't just hand us your homework and expect it to magically be done. Even if we did that, it would be dishonest on your part.

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#3 helpjav

helpjav
  • Topic Starter

  • Members
  • 7 posts
  • OFFLINE
  •  
  • Local time:09:23 AM

Posted 11 December 2011 - 01:46 PM

Sorry if my question seemed like i asked you to do the whole thing. What i meant was that i got it p all the way up to where it will display the number of sticks i specifically need help on which method shall i write for the pplayers to take thier turn and display the removal of sticks after thier turn

#4 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:07:23 AM

Posted 11 December 2011 - 01:48 PM

Java has no "Write Stick" method. You'll have to write such yourself.
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#5 helpjav

helpjav
  • Topic Starter

  • Members
  • 7 posts
  • OFFLINE
  •  
  • Local time:09:23 AM

Posted 11 December 2011 - 01:50 PM

well i know it doesnt it i was hoping you cold tell which loop i wold use i was thinking an if loop subtract a stick from each layer how wold you do it?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users