Practice: ITunesArray

So far we’ve been working with composing shape objects with GUI Java classes. Now we’re going to practice composing objects that only output to the console.

Instructions

Part I: ITunesArray

  1. Open your Java Project called ITunes_uLogin
  2. Create an ITunesArray class that:
    • Stores a list of songs as an array, and initializes the list to be empty.
    • Has a constructor that takes the maximum capacity as a parameter.
    • Has a method addSong that takes a Song as a parameter and adds it to the next open position. What should happen when the array is full?
    • Has a print method that prints the entire song list using a for each loop. It shouldn’t print empty (null) objects.
    • Has a main method that adds 3 songs to the ITunesArray class and prints them out by calling the print method.

If you don’t feel confident in Part I, STOP. Do not move on to Part II.

Part II: ITunesArray challenge methods

Add the following methods to the ITunes class and test them in main:

Demonstration

In class.