Results 1 to 2 of 2
  1. #1
    shodai is offline Senior Member
    Join Date
    Apr 2012
    Posts
    106
    Rep Power
    0

    Default Error using Abstract Classes

    I am stuck. It seems like I have done everything by the book but I keep getting the same error: cannot find symbol. The error is specifically addressing lines 9, 10, and 11 in the Alien class file. All that is suppossed to happen is an output of information for the two types of aliens.

    Java Code:
    import javax.swing.*;
    public class CreateAliens
    {
      public static void main (String[] args)
      {
        Martian aMartian = new Martian();
        Jupiterian aJupiterian = new Jupiterian();
        
        JOptionPane.showMessageDialog
          (null, "\nMartian and Jupiterian Descriptions: \n" +
           aMartian.toString() + "\n" + aJupiterian.toString());
      }
    }
    Java Code:
    public abstract class Alien
    {
      private int numEyes;
      protected int numLegs;
      protected int numArms;
      
      public Alien(int numEyes, int numLegs, int numArms)
      {
        setNumEyes(numEyes);
        setNumLegs(numLegs);
        setNumArms(numArms);
      }
      
      public int getNumEyes()
      {
        return numEyes;
      }
      
      public int getNumLegs()
      {
        return numLegs;
      }
      
      public int getNumArms()
      {
        return numArms;
      }
      
      public String toString()
      {
        return ("The alien has " + getNumEyes() + " eyes, " +
                getNumLegs() + " legs, and " + getNumArms() + " arms.");
      }
    }
    Java Code:
    import javax.swing.*;
    
    public class Martian extends Alien
    {
      public Martian()
      {
        super(2, 3, 1); //sets 2 eyes, 3 legs, and 1 arm
      }
      
      public String toString()
      {
        return("The Martian has " + getNumEyes() + " eyes, " +
                getNumLegs() + " legs, and " + getNumArms() + " arms.");
      }  
    }
    Java Code:
    import javax.swing.*;
    
    public class Jupiterian extends Alien
    {
      public Jupiterian()
      {
        super(1,4,2);
      }
       
      public String toString()
      {
        return("The Jupiterian has " + getNumEyes() + " eyes, " +
                getNumLegs() + " legs, and " + getNumArms() + " arms.");
      }
    }

  2. #2
    pj6444 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    165
    Rep Power
    2

    Default Re: Error using Abstract Classes

    You have no set methods. So, what you need to do is create set methods in your abstract Alien class.

Similar Threads

  1. when to use abstract classes
    By gauravdrocker in forum New To Java
    Replies: 6
    Last Post: 06-28-2013, 03:24 PM
  2. abstract classes
    By droidus in forum New To Java
    Replies: 1
    Last Post: 12-09-2012, 03:44 AM
  3. Help with Abstract Classes please.
    By fatabass in forum New To Java
    Replies: 1
    Last Post: 03-23-2012, 04:26 AM
  4. Abstract Classes.
    By maknib in forum New To Java
    Replies: 3
    Last Post: 05-12-2011, 03:30 PM
  5. abstract classes
    By renju krishnan in forum New To Java
    Replies: 1
    Last Post: 09-29-2010, 09:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •