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

This are API\'s and it need to be typed in Java Langauge. Thanks. Player Class A

ID: 3815607 • Letter: T

Question

This are API's and it need to be typed in Java Langauge. Thanks.

Player Class API Methods: IgetNameelO Identifier: Parameters Return Value String-A String representing the name of this Item Other iComputerControlled Identifier: Parameters Iboolean-Whether or not the player is a computer AIopponent Return Value Other Parameter pileSize-The number of marbles remaining in the pile int-The number of marbles removed the AI opponent Return Value Other: This method should be used to allow a computer controlled player to take their tum. The method works by randomly determining whether the AI will make an ideal move based on the predefined probability for that AI opponent. If an ideal move is to be made, the AI will attempt to leave the pile with some multiple of fo ur marbles If it is not possible to make an ideal move, or the AI decides not to make an ideal move, it will instead randomly choose to remove one, two, or three marbles assuming there are a sufficient number remaining on the pile, otherwise it will remove between one and the number of marbles Constructor Methods: Identifier: Player String name Parameter name-A String representing the name of this Player Return Value Other This constructor method should be used for setting up human opponents Identifier: Player String name, int idealMoveProbability) Parameters name A String representing the name of this Player An int representing the probability that the AI will make an ideal move on its Return Value: Other: This constructor method should be used for setting up computer opponents. The value for idealMoveProbability should be in the range 0 100, where 0 indicates it will never try to make an ideal move and 100 indicates that the AI will alw to make an ideal move Factory Methods: IgetirembleATPaverinstance Identifier: Parameters Return Value Player-a computer controlled player that plays badly Other: This factory method should create an instance ofthe Player class that will never attempt to make an ideal move though they still randomly make one ure chance) when is their turn IgetBadaPayernstanceO Identifier: Parameters Return Value Player-a computer controlled player that plays poorly Other: This factory method should create an instance of the Player class that will only attempt to make an ideal move approximately one-third of the time when it is their tum.

Explanation / Answer

Here is the code for you:

import java.util.*;
class Player
{
    String name;
    boolean computerControlled;
    int idealMoveProbability;
    public String getName()
    {
       //Returns a String representing the name of this Item.
       return name;
    }
    public boolean isComputerControlled()
    {
       //Returns a boolean whether or not the player is a computer AI opponent.
       return computerControlled;
    }
    public int takeComputerTurn(int pileSize)
    {
       //Given the pileSize, the number of marbles remaining in the pile, returns
       //the number of marbles removed by the AI opponent.
       boolean idealMove = true;
       Random rnd = new Random();
       if(rnd.nextInt(101) < idealMoveProbability)
           idealMove = true;
       if(idealMove)
       {
          if(pileSize > 4)
              return pileSize % 4;   //Make an attempt to leave the pile with a multiple of 4.
          return rnd.nextInt(pileSize-1) + 1;  
       }
       else
           return rnd.nextInt(pileSize-1) + 1;
    }
    public Player(String name)
    {
       //Parameterized constructor which intializes the name.
       this.name = name;
    }
    public Player(String name, int idealMoveProbability)
    {
       //Parameterized constructor which initialized 2 variables.
       this.name = name;
       this.idealMoveProbability = idealMoveProbability;
    }
    public Player getTerribleAIPlayerInstance()
    {
       Player computer = new Player("Computer", 0);
       return computer;
    }
    public Player getBadAIPlayerInstance()
    {
       Player computer = new Player("Computer", 33);
       return computer;
    }
      
}