Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. Prepare a \"read me\" file for your program Create a file named readne doc th

ID: 3726851 • Letter: 3

Question

3. Prepare a "read me" file for your program Create a file named readne doc that describes the design of your Nim program. It should briefly describe each class, the relationships among the classes (use UML diagrams), and how to use your program. Finally, briefly explain (in the readme file) how your design can casily adapt with the following changes: i) ii) If instead of one pile of stones, the game introduces three (or n) piles iii) If the game needs to be played between two computers(i.e., both the If we want to introduce a new player, who will select a move following a different strategy of stones with different sizes. players are computers). We will evaluate your program on the quality of the design and implementation, For example, iHow well are the responsibilities apportioned to independent objects that collaborate to solve the problem? ii How flexible is the design in the face of reasonable changes to the Your code and your "read me" file are the only ways you have to communicate your design and implementation, so try to use them to communicate well. A Specification for a Program to Play Nim The game of Nim consists of two players and a pile of sticks or stones. The players alternat picks up the last stone loses the game. e turns, which consist of picking up one, hwo, or three stones. The player who Your program should allow the user to play a number of games of Nim against the computer, displaying results of the play to the user Your initial implementation provide only a few simple behaviors: Allow the user to specify the number of stones to be used for the game. Allow the user to specify which player goes first.

Explanation / Answer

package algo;

import java.util.Scanner;

public class NimGame {
private static int stones;
   public static void main(String[] args) {
       playGame();
   }

   public static void playGame() {
       Scanner sc = new Scanner(System.in);
       System.out.println("Please enter the number of stones to be used in this game : ");
       stones = sc.nextInt();
       sc.nextLine();
       System.out.println("Enter Your Name");
       String name = sc.nextLine();
       int choice;
       // To read Id
       while (true) { // Condition in while loop is always true here
           System.out.println(
                   "Which player will start the game ? Select a number from the following 1.Computer 2." + name);
           choice = sc.nextInt();

           if (choice < 1 && choice > 3) {
               System.out.println("Invalid Choice .Try again ....");
               continue;
           } else {
               break;
           }
       }
       if (choice == 1) {
           int computerStones,playerStones;
           while(stones!=0)
           {
           //Minimum 1 stone has to be taken , so generating random number accordingly
           computerStones=(int) (Math.random()*(stones - 1)) + 1;
           System.out.println("Computer takes "+computerStones+" Stones ,there are "+(stones-computerStones)+" stones are remaining ");
           stones-=computerStones;
           if(stones==0)
           {
           System.out.println("Computer Has taken last stone and lost the game");  
           }
           while (true) { // Condition in while loop is always true here
               System.out.println("Please enter How many(1, 2 or 3) stones you want to take from the pile of "+stones+" stones");  
               playerStones=sc.nextInt();
                   if (playerStones > stones) {
                       System.out.println("Invalid Choice .Try again ....");
                       continue;
                   } else {
                   break;
               }
           }
           stones-=playerStones;
           if(stones==0)
           {
           System.out.println(name+" Has taken last stone and lost the game");  
           }
           }
       }
       if (choice == 2) {
           int computerStones,playerStones;
           while(stones!=0)
           {
           while (true) { // Condition in while loop is always true here
               System.out.println("Please enter How many(1, 2 or 3) stones you want to take from the pile of "+stones+" stones");  
               playerStones=sc.nextInt();
                   if (playerStones > stones) {
                       System.out.println("Invalid Choice .Try again ....");
                       continue;
                   } else {
                   break;
               }
           }
           stones-=playerStones;
           if(stones==0)
           {
           System.out.println(name+" Has taken last stone and lost the game");  
           }
           //Minimum 1 stone has to be taken , so generating random number accordingly
           computerStones=(int) (Math.random()*(stones - 1)) + 1;
           System.out.println("Computer takes "+computerStones+"Stones ,there are "+(stones-computerStones)+" stones are remaining ");
           stones-=computerStones;
           if(stones==0)
           {
           System.out.println("Computer Has taken last stone and lost the game");  
           }
       }
       }
   }

}

Output

Please enter the number of stones to be used in this game :
25
Enter Your Name
Waseem
Which player will start the game ? Select a number from the following
1.Computer
2.Waseem
1
Computer takes 2 Stones ,there are 23 stones are remaining
Please enter How many(1, 2 or 3) stones you want to take from the pile of 23 stones
5
Computer takes 14 Stones ,there are 4 stones are remaining
Please enter How many(1, 2 or 3) stones you want to take from the pile of 4 stones
2
Computer takes 1 Stones ,there are 1 stones are remaining
Please enter How many(1, 2 or 3) stones you want to take from the pile of 1 stones
2
Invalid Choice .Try again ....
Please enter How many(1, 2 or 3) stones you want to take from the pile of 1 stones
1
Waseem Has taken last stone and lost the game

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote