Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Class Team.java starts here
- // "Class Team only needs object variables for name, players and maximum size, remove the rest"
- import java.util.ArrayList;
- public class Team {
- private String teamName;
- private ArrayList<Player> playerList;
- private int size; // amount of players in a team
- private int maxSize; // max team size
- private int totalGoals; // I can't have this :(
- public Team(String teamName) {
- this.teamName = teamName;
- this.playerList = new ArrayList<Player>();
- this.size = 0;
- this.maxSize = 16;
- }
- public int goals() { // how do I make this return the total amount of goals without the variable totalGoals
- this.totalGoals = 0;
- for (Player a : this.playerList) {
- this.totalGoals = this.totalGoals + a.goals();
- }
- return this.totalGoals;
- }
- // you can ignore the rest of this class
- public String getName() {
- return this.teamName;
- }
- public void addPlayer(Player player) {
- if (this.size < this.maxSize) {
- this.playerList.add(player);
- this.size++;
- }
- }
- public void printPlayers() {
- for (Player a : this.playerList) {
- System.out.println(a);
- }
- }
- public void setMaxSize(int maxSize) {
- this.maxSize = maxSize;
- }
- public int size() {
- return this.size;
- }
- }
- // Class Player.java starts here
- public class Player {
- private String playerName;
- private int goals;
- public Player (String playerName , int goals) {
- this.playerName = playerName;
- this.goals = goals;
- }
- public Player (String playerName) {
- this.playerName = playerName;
- }
- public String getName() {
- return this.playerName;
- }
- public int goals() {
- return this.goals;
- }
- public String toString() {
- return "Player: " + this.playerName + ", goals: " + this.goals;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement