3. Fill up both teams with players. 4. Try inserting more players after filling them and handle the exception. 5. Test to see if contains is consistent in its results. 6. Finally, iterate over the team rosters and legibly output all the players.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 2PE
icon
Related questions
Question

Java

learned
building a Team, and the Player for a sport and test them out with Iterators.
Player
The players in the team should be represented by a Player class that has a name, and a position (their
number on the team). It also needs a default constructor (no arguments) that gives a default name and
position of 0. Two instances of Player are equal to each other when the name and position is equal.
Team
A team has a name, a roster of players (an ArrayList), and a maximum number of players. Make use of
the Iterator from the roster to implement the following:
We'll be
contains: Check if a Player is in the roster.
insert: Insert a Player into the roster. Cannot add a duplicate player, and you cannot add
more than the maximum number of players. Throw an exception in those cases like so:
public void makeError () throws Exception {
}
throw new Exception ("This is an exception message.");
iterator: A public method to expose the iterator for your roster of players.
Don't use anything other than the iterator, size, and add method from your ArrayList variable.
Transcribed Image Text:learned building a Team, and the Player for a sport and test them out with Iterators. Player The players in the team should be represented by a Player class that has a name, and a position (their number on the team). It also needs a default constructor (no arguments) that gives a default name and position of 0. Two instances of Player are equal to each other when the name and position is equal. Team A team has a name, a roster of players (an ArrayList), and a maximum number of players. Make use of the Iterator from the roster to implement the following: We'll be contains: Check if a Player is in the roster. insert: Insert a Player into the roster. Cannot add a duplicate player, and you cannot add more than the maximum number of players. Throw an exception in those cases like so: public void makeError () throws Exception { } throw new Exception ("This is an exception message."); iterator: A public method to expose the iterator for your roster of players. Don't use anything other than the iterator, size, and add method from your ArrayList variable.
Let's run some tests to ensure that your code is running correctly!
1. Create Team A, a team with the name "Tigers". Create another team, Team B, using the default
constructor. The maximum number of players should be 17.
2.
Add two players built with the default constructor to Team A and catch the exception that is
thrown using a try/catch statement. In the catch section, print the stack trace or another helpful
message:
try {
throw new Exception ("This is an exception message.");
catch (Exception e) {
e.printStackTrace ();
3. Fill up both teams with players.
4. Try inserting more players after filling them and handle the exception.
5. Test to see if contains is consistent in its results.
6. Finally, iterate over the team rosters and legibly output all the players.
Transcribed Image Text:Let's run some tests to ensure that your code is running correctly! 1. Create Team A, a team with the name "Tigers". Create another team, Team B, using the default constructor. The maximum number of players should be 17. 2. Add two players built with the default constructor to Team A and catch the exception that is thrown using a try/catch statement. In the catch section, print the stack trace or another helpful message: try { throw new Exception ("This is an exception message."); catch (Exception e) { e.printStackTrace (); 3. Fill up both teams with players. 4. Try inserting more players after filling them and handle the exception. 5. Test to see if contains is consistent in its results. 6. Finally, iterate over the team rosters and legibly output all the players.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Exception Handling Keywords
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
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,