CS116      Lab 7 - Creating Classes

Objectives:

  1. Before starting this lab you should have read chapter 11 in your text.
     
  2. Open DrJava. 
     


  3.  
    Assignment:
    Define a class Song.  This class will have fields for the title of the song, the Sound object for the song, and the number of times that the song has been played. 

    Create a constructor for this class in which you will provide the title and the Sound object.  Initially the number of times played should be zero and therefore does not need to be sent as a parameter to the constructor.

    Write a method play() which plays the song.
    Write a method getTitle() which returns the String value for the title of the song.
    Write a method getTimesPlayed() which returns the integer value for the number of times that the song has been played.


     


  4.  

    Assignment:
    Define a class Slideshow which has two arrays as fields:  an array of pictures, and an array of sounds. 
    The constructor for this class will let users pass two arrays when creating a new Slideshow object.
    The class will have a method show() that plays the slideshow.  It should display each picture in its array, one at a time.  While the picture is showing, your object should play the corresponding sound file.

    Write a main program which builds two arrays, creates a Slideshow object, and plays the slideshow.

    Hints:  In order to wait for the entire sound to play before moving on to the next picture, you can use the blockingPlay() method of the Sound class.

    If you wish to pause between pictures the following code will cause your program to wait for the specified amount of time (in this example it would be 2000 milliseconds or two seconds):
       try{
          Thread.sleep(2000);
        }catch(InterruptedException e){};

    You will need to import the Thread class:
        import java.lang.Thread;


     

  5. Send your Song.java and SlideShow.java classes to me using using GoucherLearn.