Play a) Given an index and a position, play the player found at the specified index in the players array in a league match in the given position on the pitch. b) If the given position is the player's preferred position, subtract a random integer in the range [1, 5] from the player's current stamina. c) If the given position is not the player's preferred position but is a position this player can play, subtract a random integer in the range [5, 10] from the player's current stamina. d) If the position passed is not a position the player can play, print out "This player cannot be played in position {position}.", and return from the method. e) If the player at the specified index is played in the league match, print out the player with the updated stamina in the following format on its own line: "Played: {player}". f) If the index is invalid, or there is not a player at the specified index, print "Cannot play the player in this spot." on its own line.

icon
Related questions
Question

Given Enum.java, Data.java which may have overlapping variables and the following start:

public enum Position {

Attacker, Midfield, Defender, Goalie
}


public class Team {

//Variables

private Player[] players;
    private int squadSize;

// Two Constructors  
    public Team(Player[] players) {
        this.players = players;
        this.size = players.length;
    }

    public Team() {
        this.players = new Player[4]; 
        this.size = 0; 
    }

}

How would I go about creating the given method named 'Play'? 

public class Data {
private String Name;
private int Endurance;
private Position [] positions;
private int Rating;
}
}
public Data (String Name, int Endurance, Position [] positions, int Rating) {
this.Name = Name;
}
public Data (String Name, Position [] positons) {
this.Name = Name;
this.Endurance = Endurance;
this.positions = positions;
this.Rating = Rating;
}
public Data (){
this.Endurance = 50;
this.positions
this.Rating
=
}
=
70;
}
positons;
this.Name = "Botman";
}
public boolean trainAbility() {
return skillRating >= 50 && skillRating <= 89;
this. Endurance = 50;
this.positions = new Position[]{Position.defender};
this.Rating = 70;
public Position maxPosition() {
return positions [0];
}
public Position[] getPositions() {
return positions;
}
public boolean other Positions (Position position ToCheck) {
for (Position position : getPositions()) {
if (position == positionToCheck) {
return true;
}
}
return false;
public String toString() {
return String.format("<%s,%d,%s,%d,%b>", Name, Endurance, maxPosition(), Rating, trainAbility());
Transcribed Image Text:public class Data { private String Name; private int Endurance; private Position [] positions; private int Rating; } } public Data (String Name, int Endurance, Position [] positions, int Rating) { this.Name = Name; } public Data (String Name, Position [] positons) { this.Name = Name; this.Endurance = Endurance; this.positions = positions; this.Rating = Rating; } public Data (){ this.Endurance = 50; this.positions this.Rating = } = 70; } positons; this.Name = "Botman"; } public boolean trainAbility() { return skillRating >= 50 && skillRating <= 89; this. Endurance = 50; this.positions = new Position[]{Position.defender}; this.Rating = 70; public Position maxPosition() { return positions [0]; } public Position[] getPositions() { return positions; } public boolean other Positions (Position position ToCheck) { for (Position position : getPositions()) { if (position == positionToCheck) { return true; } } return false; public String toString() { return String.format("<%s,%d,%s,%d,%b>", Name, Endurance, maxPosition(), Rating, trainAbility());
Play
a) Given an index and a position, play the player found at the specified index in the
players array in a league match in the given position on the pitch.
b)
If the given position is the player's preferred position, subtract a random integer
in the range [1, 5] from the player's current stamina.
c)
If the given position is not the player's preferred position but is a position this
player can play, subtract a random integer in the range [5, 10] from the player's
current stamina.
d)
If the position passed is not a position the player can play, print out "This player
cannot be played in position {position}.”, and return from the method.
e)
If the player at the specified index is played in the league match, print out the
player with the updated stamina in the following format on its own line: "Played:
{player}".
f)
If the index is invalid, or there is not a player at the specified index, print “Cannot
play the player in this spot." on its own line.
Transcribed Image Text:Play a) Given an index and a position, play the player found at the specified index in the players array in a league match in the given position on the pitch. b) If the given position is the player's preferred position, subtract a random integer in the range [1, 5] from the player's current stamina. c) If the given position is not the player's preferred position but is a position this player can play, subtract a random integer in the range [5, 10] from the player's current stamina. d) If the position passed is not a position the player can play, print out "This player cannot be played in position {position}.”, and return from the method. e) If the player at the specified index is played in the league match, print out the player with the updated stamina in the following format on its own line: "Played: {player}". f) If the index is invalid, or there is not a player at the specified index, print “Cannot play the player in this spot." on its own line.
Expert Solution
steps

Step by step

Solved in 5 steps with 4 images

Blurred answer