Question
Create New Class named BaseballRoster to store the roster details Declare 5 fields as follows (including initializations if stated): 2 fields named city and name
Create New Class named BaseballRoster to store the roster details Declare 5 fields as follows (including initializations if stated): 2 fields named city and name of type String field named year of type int field named positions of type array of String with: initialization to literal values of MGR, P, C, 1B, 2B, 3B, SS, LF, CF, RF field named players of type array of String with: initialization to SAME # of elements as in positions (use its .length field) Write constructor to initialize all fields (except positions) to the parameters public BaseballRoster(String city, String name, int year, String manager) MUST: use formatString( ) for all type String parameters before assignment MUST: use findIndex( ) to get the proper index for the manager assignment Add accessors getCity, getName and getYear to return the corresponding fields Add accessors getPositions and getPlayers to return the array of String fields Add accessor toString( ) to return a String in the format: Add accessor getPlayerString(int index) to return a String in the format: Add formatString(String oldString) to return String with leading and trailing spaces removed (use .trim) & letters ALL in uppercase (use .toUpperCase) MUST: return a String (even an empty String when oldString is null) Add int findIndex(String position) returning index matching position (or 1 error) MUST: use while loop, formatString( ) and equalsIgnoreCase( ) Add String findPlayerPosition(String player) to return the String position from positions matching the player parameter in players (or NONE if not found) MUST: use while loop, formatString( ) and equalsIgnoreCase( ) Add void assignPlayerInPosition(String player, String position) to assign a certain String player to a given String position MUST: first use findIndex( ) on formatString( ) of position to get the index if returned index is valid within positions, assign formatString( ) of the player to within players at that index AND print ASSIGNED <getPlayerString( )> else print ERROR invalid position Add void takePlayerOut(String player) to take a String player out the players MUST: first use findIndex( ) on findPlayerPosition( ) of the formatString( ) of the player to get the index within players to vacate if index is valid within positions, print TAKEN OUT <getPlayerString( )> AND assign null to that index within players else print ERROR invalid player Add void printRoster( ) to print ALL players (even if N/A) with ALL positions MUST: use toString( ) to 1st print heading (i.e. 2011 CHICAGO CUBS ROSTER:) MUST: use for loop and getPlayerString( ) to print each player on its own line Add void listPlayers( ) to ONLY print the player names in players if it exists MUST: use toString( ) to 1st print heading (i.e. 2011 CHICAGO CUBS PLAYERS:) MUST: use for-each loop to print each String player in players ONLY if it exists |
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