Results 1 to 6 of 6
  1. #1
    esallender is offline Member
    Join Date
    Oct 2010
    Posts
    9
    Rep Power
    0

    Default problem with constructor

    I am having a problem with my program calling the constructor:

    heres the code:

    package p2ip;

    /**
    *
    * @author Ernest
    */
    public class main {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {

    Basic theBasic = new Basic (5.50 , "Basic" , "fName" , "lName" , "eMail","date"); //instantiates basic
    Premium thePremium = new Premium (5.50, 10, 15, "Premium", "fName", "lName", "eMail", "FaxesReceived", "FaxAllowed");//instantiates premium
    Trial theTrial = new Trial(17, "Trial", "fName", "lName", "eMail",
    "date", "FaxesSent");//instantiates trial

    Subscription currentObject;

    currentObject = theBasic;
    System.out.println(currentObject.calculateFees() + "," +
    currentObject.getfName());
    currentObject.calculateFees();

    currentObject = thePremium;
    currentObject.calculateFees();

    currentObject = theTrial;
    currentObject.calculateFees();


    }
    }

    the code th is bolded has the problem
    I have attached the whole project to a zip file. any help would be appreciated.
    Attached Files Attached Files

  2. #2
    esallender is offline Member
    Join Date
    Oct 2010
    Posts
    9
    Rep Power
    0

    Default

    I am also having problems with these lines

    Premium thePremium = new Premium (5.50, 10, 15 , "Premium", "fName", "lName", "eMail", "FaxesReceived", "FaxAllo wed");// instantiates premium
    Trial theTrial = new Trial(17, "Trial", "fName", "lName", "eMail",
    "date", "FaxesSent");//instantiates trial

  3. #3
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    post the code that defines the constructor in question please.

  4. #4
    esallender is offline Member
    Join Date
    Oct 2010
    Posts
    9
    Rep Power
    0

    Default code for Basic

    package p2ip;
    // <editor-fold defaultstate="collapsed" desc=" UML Marker ">
    // #[regen=yes,id=DCE.BFD57244-ED70-63DC-0DAC-F3B835BEAF95]
    // </editor-fold>
    public class Basic extends Subscription {

    // <editor-fold defaultstate="collapsed" desc=" UML Marker ">
    // #[regen=yes,id=DCE.B25845FE-5C9C-B54F-FE4C-CC1AB935E216]
    // </editor-fold>
    public double monthlyFee; //sets monthly fee to 5.00
    // sets string to over rides parentclass

    public Basic(double Mfee, String fName, String lName, String eMail, String date) {
    super(fName, lName, eMail, date);
    monthlyFee = Mfee;
    }

    public double calculateFees() {
    return monthlyFee;

    }

    public String toString() {
    String returnValue; // declares return value
    returnValue = String.valueOf(monthlyFee); //sets returnValue to monthlyFee
    return returnValue; //returns value of returnValue
    }
    }


    The code for Premium and trial are very similar. if we can solve the problem with this code I am sure I can figure out what went wrong withe others.


    :confused:

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,534
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by esallender View Post
    public Basic(double Mfee, String fName, String lName, String eMail, String date) { ... }
    Your constructor takes one double and four Strings as parameters; look what you did in your original post: you tried to pass a double and five Strings.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default

    Quote Originally Posted by esallender View Post
    I am having a problem with my program calling the constructor:
    You really ought to also print out the actual error you are getting.
    You should not expect us to compile your code to find out the error.

Similar Threads

  1. Problem with constructor
    By kvm in forum New To Java
    Replies: 1
    Last Post: 12-11-2010, 01:27 AM
  2. Constructor Problem
    By Aggy in forum New To Java
    Replies: 9
    Last Post: 01-19-2010, 10:42 PM
  3. Problem with using an array in a constructor
    By planesinspace in forum New To Java
    Replies: 3
    Last Post: 08-28-2009, 09:17 AM
  4. Problem with Constructor
    By ToastyBainey in forum New To Java
    Replies: 3
    Last Post: 03-09-2009, 02:36 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
  •