Lab 21: ArrayLists

In this lab we will practice using ArrayLists.

Problem 1: Lab19: UseShape

You are given the solutions from the Shape interface problem in lab19 here:

Rewrite UseShape so that it does not use arrays, but rather uses and ArrayList to hold the shapes. After you test your code to see it produces the same result as the original, add a loop to print each of the shape objects before calling the sumAreas() method.

Now, add more shapes (at least 3-4) of different types. Run the code and see that it produces reasonable results.

Problem 2: Team, Player, UseTeam

Below is some code around representing baseball players on a team:

Download and try to understand how the code is working first. Then rewrite UseTeam to use ArrayLists rather than an array that has a capacity. Remove the capacity check (and the CAPACITY variable) and test the code by adding more than 50 players (the old 'capacity') to the team.

When you are done:

When you are done with these, feel free to leave the lab.