Results 1 to 9 of 9
  1. #1
    mahirul is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

    Default Must get some help tonight

    Hello all experts,

    Please help with the following error message,

    "Cannot find symbol -constructor. here are the codes for the child and the parent class.



    public class Laptop extends MobileComputer
    {
    /*
    * Constructor for the Laptop class
    * This constructor passes most paramters back to the Computer object
    * as the only two fields unique to Laptop are builtIns and battery.
    */

    public Laptop(String theBuiltIns, String theBattery)
    {
    super (theBuiltIns, theBattery);
    }


    /************************
    * METHODS
    ************************/

    /*
    * This method will take the information stored in the Laptop class
    * and return it in a String to be used by the method calling it.
    * Parameters: none
    * Return: String
    */
    public String toString()
    {
    return "\nID: " + id + "\nQuantity: " + quantity + "\nModel: " + model + "\nManufacturer: " + manufacturer + "\nProcessor: " + processor + "\nMemory: " + memory + "\nHD/SSD: " + hdSsd + "\nDisplay: " + display + "\nBuilt-Ins: " + builtIns + "\nBattery: " + battery + "\nSuggested Retail Price: " + srp + "\n";
    }


    /************************
    * BEGINNING OF ACCESSORS
    ************************/

    public String getBuiltIns()
    {
    return builtIns;
    }

    public String getBattery()
    {
    return battery;
    }

    /************************
    * END OF ACCESSORS
    ************************/

    /************************
    * BEGINNING OF MUTATORS
    ************************/

    public void setBuiltIns(String newBuiltIns)
    {
    builtIns = newBuiltIns;
    }

    public void setBattery(String newBattery)
    {
    battery = newBattery;
    }

    /************************
    * END OF MUTATORS
    ************************/
    }





    import java.util.*;
    /**
    * Write a description of class MobileComputer here.
    *
    * @author (your name)
    * @version (a version number or a date)
    */
    public class MobileComputer extends Product
    {
    // instance variables - replace the example below with your own
    protected ArrayList<String> builtIns;
    protected String battery;
    /**
    * Constructor for objects of class MobileComputer
    */
    public MobileComputer(int theId, String theName, int theQuantity, double thePrice, String theModel, String theManufacturer, String theProcessor, String theMemory, String theDrive, String theDisplay, double theSRP, String theBuiltIns, String theBattery)

    {
    super(theId, theModel, theManufacturer, theProcessor, theMemory, theDrive, theDisplay, theSRP);
    this.builtIns = new ArrayList<String>();
    this.battery = battery;
    }

    /**
    * Constructor for objects of class MobileComputer
    */
    public void MobileComputer()
    {
    builtIns = new ArrayList<String>();
    }
    public void addBuiltInDevices(String feature)
    {
    builtIns.add(feature);
    }

    }

  2. #2
    Bertstar is offline Member
    Join Date
    Dec 2010
    Posts
    45
    Rep Power
    0

    Default

    you dont have a constructor in the parent class that takes the parameters you are trying to pass to it in the childs constructor.....


    and why do you have so many parameters in the MobileComputer constructor that you don't use?
    Last edited by Bertstar; 12-07-2010 at 05:00 AM.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    If you need help fast then a few suggestions to help you get help fast:

    1) please use an informative thread title. "Must get help" tells us little about your problem. Better would be: "Help with Cannot Find Symbol error" or something similar.
    2) Post the complete error message itself. Right now we don't know which line is causing the error.
    3) Indicate which line is causing the error with an obvious comment, such as
    Java Code:
    myFoo = 3; // ******* this line is causing the error
    4) Use code tags so your code is readable. You can learn how to use them by reading the link in my signature.

    For now though the most important thing for you to post is the actual error message and an indication of which line is causing the error.

    Luck and welcome to our forum!

    edit: looks like bertstar has found your error! Good show!

  4. #4
    mahirul is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

    Default

    How do you suggest I write the constructor in the parent class? I am fresh out of ideas.

  5. #5
    mahirul is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

    Default

    This line is causing the error

    super (theBuiltIns, theBattery);
    the error message is
    cannot find symbol-constructor MobileComputer(java.lang.String,java.lang.String)

  6. #6
    Bertstar is offline Member
    Join Date
    Dec 2010
    Posts
    45
    Rep Power
    0

    Default

    your call to the the parents constructor in Laptop has only 2 parameters while the only constructor you provide in the parent class is a constructor with 13 parameters.

    this link should help you fix your problem.

    Constructors

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    The super call can only take parameters as defined in the MobileComputer class. So that means either a default constructor -- super() with no parameters, or this one:
    Java Code:
    public MobileComputer(int theId, String theName, int theQuantity, double thePrice, String theModel, String theManufacturer, String theProcessor, String theMemory, String theDrive, String theDisplay, double theSRP, String theBuiltIns, String theBattery)
    which takes an int, String, int, double, String, String, String, String, String, String, double, String, String.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Bertstar View Post
    your call to the the parents constructor in Laptop has only 2 parameters while the only constructor you provide in the parent class is a constructor with 13 parameters.
    If I read his MobileComputer class correctly, there is a default constructor present as well.

  9. #9
    Bertstar is offline Member
    Join Date
    Dec 2010
    Posts
    45
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    If I read his MobileComputer class correctly, there is a default constructor present as well.
    Yeah your right I didn't see that.

Similar Threads

  1. Replies: 8
    Last Post: 06-06-2010, 04:10 PM
  2. Assignment due tonight, please help me!
    By twiggy62 in forum New To Java
    Replies: 4
    Last Post: 02-09-2010, 07:07 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
  •