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

This are the API\'s and need to be typed in Java language, thanks Factory Method

ID: 3815615 • Letter: T

Question

This are the API's and need to be typed in Java language, thanks

Factory Methods getrenible ATPavernstanceo Identifier: Parameters Return Value: Plaver a computer controlled player that plays badly Other This factory method should create an instance of the Player class that will never attempt to make an ideal move (although they still may randomly make one by pure chance) when it is their turn getBadAplaverinstanceo Identifier: Parameters Return Value: Plaver 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 Identifier: Parameters Return Value: Player- a computer controlled player that plays somewhat intelligently. Other: This factory method should create an instance of the Player class that will only attempt to make an ideal move approximately two-thirds of the time when it is their turn geExcellentyPlaverinstance Identifier: Parameters Return Value: Plaver a computer controlled player that always plays ideally Other This factory method should create an instance of the Player class that will always attempt to make an ideal move whenever possible and should never put themselves in a losing state

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;
    }
      
}