Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

(e.x. 2013 PHILADELPHIA PHILLIES)

Add accessor getPlayerString(int index) to return a String in the format:

() (e.x. RYAN HOWARD (1B)) OR N/A () (e.x. N/A (1B)) if no player in the position

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago