Amanda's SnowPerson

The SP Version

First I thought about the design and what I needed. The snowperson's face is comprised of a filled white oval, with a square nose, a mouth, and two eyes with two pupils...

I figured that it is not a good coding convention to have everything instantiated in the applet. So, I decided that the applet would instantiate one thing and that thing would "contain" everything else. The applet would contain the SnowFace which contained all of the components of the face.

Then I made the SnowFace class. I knew that the class it extended, cs015.SP.SnowFace, had a white filled oval in it so that I didn't have to make that. But I had to inherit it so that it would show up in my program. To do that I did the call "super()" which inherits everything from the parent class.

Then after instantiating the eyes, the nose, and the mouth I was done...so I compiled. I got two errors: /u/aks/wave/src/SnowPerson/SnowFace.java:19: Class SnowPerson.OvalMouth not found in type declaration. They were both the same. They had arisen because I forgot to put the cs015.SP in front of OvalMouth so they didn't know what kind of ovalMouth I wanted. So I put it there and everything compiled correctly...

I have decided to color the code to make it clearer to beginners what text means what...the text in teal is comments, the text in red are reserved words (this means that they cannot be used as class or variable names, to avoid confusion for the compiler,) the rest of the words taht are in black are words that I used as my variable and class names. They don't have to be specific words, just as long as you are consistent.The code in green are type names. The code in purple are variable names.

This is the code:


Applet


package SnowPerson;


/** 
 *  Package SnowPerson 
 *  class SnowFace 
 *
 *  This class is just the applet, it instantiates everything we need to
 *  have the applet run, everything...which is one thing...which is the
 *  SnowFace.
 *  author aks
 */


public class  Applet extends cs015.SP.Applet {

  private SnowFace _myFace;

  public Applet() {

    this.super();

    
    /* the call super() means that it inherits everything fromt the class 
     * it extends...in this case it inherits from a class that instantiates 
     * a frame and puts things inside.
     */

    _myFace = new SnowFace();

    
    /* this just instantiates the SnowFace class that I have created */
    
  }

}

SnowFace

package SnowPerson;

/**
 *  Package SnowPerson 
 *  class SnowFace 
 *
 *  This class will instantiate all of the components of the face so that 
 *  the applet does not have to do it...  The SnowPerson's face needs to
 *  have certain components in it...it has to have eyes, a nose, and a
 *  mouth.  Since the class it extends, cs015.SP.SnowFace has a filled
 *  white oval in it, we don't have to do anything about that
 *  author aks
 */

public class SnowFace extends cs015.SP.SnowFace {

  private cs015.SP.RoundEyes _eyes;
  private cs015.SP.SquareNose _nose;
  private cs015.SP.OvalMouth _mouth;
 
  /* above, I declared the instance variables that will be maintained
     throughout the rest of the class.  IF I instantiate them later
     I won't need to declare their types.
  */

  public SnowFace () {

    super();  //I call this so that I inherit that circle for a face
    _eyes = new cs015.SP.RoundEyes();
    _nose = new cs015.SP.SquareNose();
    _mouth = new cs015.SP.OvalMouth();
    /*above I instantiate all of the components of the face*/
  }

}



If you have questions just mail me... Amanda.


Reactions