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.
Song
& ITunes
basicRx: <15 min Av: 15-30 min Sd: 30-45 min DNF: 45+ min
ITunes_uLogin
Song
class with:
Source > Generate Getters & Setters
and clicking Select All
.toString
is a special Java method that returns a string representation of an object. When we don’t define a toString
method and we try to print an object, we get its location in memory instead!ITunes
class that:
ArrayList
, and initializes the list to be empty.addSong
to the ITunes
class that adds a song to the ArrayList
.print
method that prints the entire song list using a for each loop.main
method that adds 3 songs to the iTunes
class without using the default constructor, 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.
ITunes
challenge methodsRx: <10 min Av: 10-20 min Sd: 20-30 min DNF: 31+ min
Add the following methods to the ITunes
class and test them in main
:
getTotalPrice
method that returns the total cost of the entire song list.getMinimumPrice
method that returns a Song
with the lowest price in the listIn class.