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.
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.
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'?
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 5 steps with 4 images