Question
Java OOP: Help please Here is how i want it: when i pass in values into SoccerTeam class(like examples in the test cases), it will
Java OOP: Help please
Here is how i want it: when i pass in values into SoccerTeam class(like examples in the test cases), it will store the values in an object(Player) and save that object into an arrayList in SoccerTeam. ---------------------------------------------------------------------------------------
//Player Class: this is an object player, will store numsubmission, goals, and name.
public class player(){
//must implemenet this class
}
----------------------------------------------------------------------------------------------
public class SoccerTeam { private ArrayList list;
//Must use arraylist, string, and math only. Do not use anything else //maximum file submission for a player is 10
//initialize everything here public SoccerTeam(int maxSubmission) { list = new ArrayList(maxSubmission); }
//add player to team, check for null and empty public boolean addPlayer(String newPlayer) { Player player = new Player(newPlayer);
list.add(player); } //return how many team member is in a team public int numTeamMember() { throw new UnsupportedOperationException("You must write this method."); } //add the file of the player //ex, Juan scored goal = [ 1,1,1,2,1] //it should store 6 goals, and Juan. So that when calls for juan, it should return 6 goals public boolean addFile(String name, int[] Goal) { throw new UnsupportedOperationException("You must write this method."); } //return the total goal of a specific object player, check for empty, not added name public int goals(String name) { throw new UnsupportedOperationException("You must write this method."); } //how many file the player submitted public int numFile() { throw new UnsupportedOperationException("You must write this method."); }
}
----------------------------------------------------------------------------------------------------------
-------------------------------------------------------------
test cases: SoccerTeam socTeam= new SoccerTeam(10);
socTeam.addPlayer("Juan Garcia"); socTeam.addPlayer("Tom hank"); assertFalse(socTeam.addPlayer("")); // this one should return false
socTeam.addPlayer("Alex Murphy"); socTeam.addPlayer("Juan Garcia"); // same name with first add assertEquals(3, socTeam.numTeamMember()); assertEquals(0, socTeam.File("Tom Garcia")); socTeam.addPlayer("Tom Tom"); socTeam.addFile("Tom Tom", new int[]{1, 1, 1, 5, 1});
assertEquals(1, socTeam.File("Tom Tom")); assertEquals(9, socTeam.goals("Tom Tom"));
socTeam.addFile("Jess Chia", new int[]{5, 5, 1}); socTeam.addFile("Jess Chia", new int[]{2, 1, 0}); assertEquals(2, socTeam.numFile("Jess Chia")); assertEquals(11, socTeam.goals("Jess Chia"));//lowering goal does not replace higher goal file }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started