12.07.2015 Views

Homework (.pdf) - thecubscientist.com

Homework (.pdf) - thecubscientist.com

Homework (.pdf) - thecubscientist.com

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

P5E. Create a class called “Jukebox”. A “Jukebox” will consist of a 2D array ofMySong objects called songList. Write a program to perform the following tasks:a. Write a zero-argument constructor to fill the jukebox with the followingMySong objects and ratings or fill with your own songs. You can cut and pastethe following code to quickly fill up your jukebox free of charge…songList[0][0] = new MySong( "Jet Airliner", 5 );songList[0][1] = new MySong( "Slide", 4 );songList[0][2] = new MySong( "Tom Sawyer", 3 );songList[0][3] = new MySong( "Purple Rain", 2 );songList[1][0] = new MySong( "Sing a Song", 1 );songList[1][1] = new MySong( "Baba O'Riley", 5 );songList[1][2] = new MySong( "Jumper", 4 );songList[1][3] = new MySong( "Car Wash", 3 );songList[2][0] = new MySong( "Kung Fu Fighting", 2 );songList[2][1] = new MySong( "Right as Rain", 4 );songList[2][2] = new MySong( "Beat It", 5 );songList[2][3] = new MySong( "Bust a Move", 4 );b. Write a toString() method that will traverse the 2D array songList andprint all songs in the “Jukebox” using nested for-each loops. Design yourtoString() method to print out the songs in the “Jukebox” in a userfriendlyformat.c. Write a method randomSong() that randomly picks a song to play. This canbe done by using Math.random() to pick random numbers for a row and acolumn in the “Jukebox” and prints the name of the song at that location.Make sure that your code picks row/column <strong>com</strong>binations that are within thebounds of the 2D array.d. Finally, write a method playSongofRating( int rating ) that takesan integer argument and prints only those songs in the “Jukebox” whoserating is equal to the parameter rating.Page 4AP Computer Science – HW Set 5 Programshttp://<strong>thecubscientist</strong>.<strong>com</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!