CS116      Lab 7 - Creating Classes

Objectives:

  1. Before starting this lab you should have read chapter 11 in your text.
     
  2. Open Eclipse and import the cs116 project. 
     
  3. Open up the source code for the class Cartoon.java.  Let's take a closer look at what makes up a class definition. 

    A class may contain "fields".  These fields are instance variables containing that data for objects of that class.  For the Cartoon class, every cartoon will contain data for the Picture of the cartoon.

    A class will have at least one constructor which will always be named the same as the class name.  A class may have several constructors which take different arguments and the proper one will be used depending on what arguments are provided.  This is called overloading.  For the Cartoon class we have one constructor which takes a Picture as argument.  The instance variable is then set to be this picture.

    A class can have many methods which specify operations that can be performed on objects of the class.  The Cartoon class has a method addWordBallon.

    A class may optionally have a main program which can be executed as an application.
     
  4. Section 11.4 in your text explains how to declare and initialize an array.  Also, a field in a class may be an array of values.
     

    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. Email your class SlideShow.java  to me at jill.zimmerman@goucher.edu