Given Enum.java, Data.java (which may have overlapping variables), and the following start of Player.java : 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'?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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

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'? 

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.
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 == position ToCheck) {
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 == position ToCheck) { return true; } } return false; public String toString() { return String.format("<%s,%d,%s,%d,%b>", Name, Endurance, maxPosition(), Rating, trainAbility());
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Introduction to Interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education