Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a Java Expert!

Join 244,284 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,024 people online right now. Registration is fast and FREE... Join Now!




compiler error

 
Reply to this topicStart new topic

compiler error

isale8888
10 Nov, 2008 - 06:43 PM
Post #1

New D.I.C Head
*

Joined: 29 Oct, 2008
Posts: 43



Thanked: 1 times
My Contributions
Im working with inheritanceand I have to make a class payment, and two class derived from the class payment, which are cashpayment and creditcardpayment.

My cashpayment is working ok, but when I try to compile my creditcardpayment it promtps me the next message

"cannot find symbol "constructor" creditcardpayment....

I havent finished yet my creditcardpayment class, but I believe I did the constructor



This my class Payment
CODE

public class Payment {
  
    private double amount;

      public Payment() {
        amount = 0.0;
    }

      public Payment(double paymentAmount) {
        amount = paymentAmount;
    }

      public void setPayment(double paymentAmount) {
        amount = paymentAmount;
    }

      public double getPayment() {
        return amount;
    }

      public void paymentDetails() {
        System.out.println("The payment amount is " + amount);
    }

     public static void main(String[] args) {
        // Create several test classes and invoke the paymentDetails method
        Payment cash1 = new CashPayment(50.5);
        Payment cash2 = new CashPayment(20.45);
        Payment credit1 =  new CreditCardPayment(10.5, "Fred", "10/5/2010", "123456789");
        Payment credit2 =  new CreditCardPayment(100, "Barney", "11/15/2009", "987654321");

        System.out.println("Cash 1 details:");
        cash1.paymentDetails();
        System.out.println();
        System.out.println("Cash 2 details:");
        cash2.paymentDetails();
        System.out.println();

        System.out.println("Credit 1 details:");
        credit1.paymentDetails();
        System.out.println();
        System.out.println("Credit 2 details:");
        credit2.paymentDetails();
        System.out.println();
    }
}


and this is what I got so fr for the creditcard payment class

CODE

public class CreditCardPayment extends Payment {
  public CreditCardPayment() {
      super();
  }

  public CreditCardPayment(double paymentAmount) {
    super(paymentAmount);
  }

  public String getCardName() {
    return cardName;
  }

  public void setCardName(String cardName) {
    this.cardName = cardName;
  }
  
  
  
  
  private String cardName;
}


and this is my creditcardpayment class, so far

public class CreditCardPayment extends Payment {
  public CreditCardPayment() {
      super();
  }

  public CreditCardPayment(double paymentAmount) {
    super(paymentAmount);
  }

  public String getCardName() {
    return cardName;
  }

  public void setCardName(String cardName) {
    this.cardName = cardName;
  }
  
  private String cardName;
}

can you guys help me with this error? I have done the creditcashpayment class in different ways, but I still get the same compiling error, and that doesnt happen with my cashpayment class. I have checked over and over and I cant find whats wrong

*Edited to add the [ code] tags so we can read your code. In the future please code.gif

This post has been edited by pbl: 10 Nov, 2008 - 06:52 PM

User is offlineProfile CardPM
+Quote Post


pbl
RE: Compiler Error
10 Nov, 2008 - 06:56 PM
Post #2

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 6,951



Thanked: 673 times
Dream Kudos: 200
My Contributions
You posted twice your CreditCardPayment class
but not your CashPayment one
User is offlineProfile CardPM
+Quote Post

Locke
RE: Compiler Error
10 Nov, 2008 - 07:06 PM
Post #3

I am *not* a Thief...I *prefer* TREASURE HUNTER!
Group Icon

Joined: 20 Mar, 2008
Posts: 2,808



Thanked: 185 times
Dream Kudos: 325
Expert In: Java

My Contributions
QUOTE(pbl @ 10 Nov, 2008 - 06:56 PM) *

You posted twice your CreditCardPayment class
but not your CashPayment one


Yeah, and we might need that one to figure out what's going on...

Also, what comes to mind with that error is the parameter passing. Check to make sure you've defined a constructor for how many variables you're passing to it.

This post has been edited by Locke37: 10 Nov, 2008 - 07:09 PM
User is offlineProfile CardPM
+Quote Post

pbl
RE: Compiler Error
10 Nov, 2008 - 07:16 PM
Post #4

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 6,951



Thanked: 673 times
Dream Kudos: 200
My Contributions
QUOTE(Locke37 @ 10 Nov, 2008 - 07:06 PM) *

QUOTE(pbl @ 10 Nov, 2008 - 06:56 PM) *

You posted twice your CreditCardPayment class
but not your CashPayment one


Yeah, and we might need that one to figure out what's going on...

Also, what comes to mind with that error is the parameter passing. Check to make sure you've defined a constructor for how many variables you're passing to it.

Locke you are too fast
Actually these constructors are not defined

CODE

        Payment cash1 = new CashPayment(50.5);
        Payment cash2 = new CashPayment(20.45);
        Payment credit1 =  new CreditCardPayment(10.5, "Fred", "10/5/2010", "123456789");
        Payment credit2 =  new CreditCardPayment(100, "Barney", "11/15/2009", "987654321");

User is offlineProfile CardPM
+Quote Post

Locke
RE: Compiler Error
10 Nov, 2008 - 07:23 PM
Post #5

I am *not* a Thief...I *prefer* TREASURE HUNTER!
Group Icon

Joined: 20 Mar, 2008
Posts: 2,808



Thanked: 185 times
Dream Kudos: 325
Expert In: Java

My Contributions
You're right, they're not.

I just threw that solution out there, I didn't even check anything! biggrin.gif

I'm better than I thought.
____________________________

You need to create constructors that exactly match the data you're going to need to pass...for instance, if I wanted to pass a first name and a last name to a NAME constructor...BUT I also want a name to be generated if the name is unknown...

java
public class NAME
{
public String firstName;
public String lastName;

public NAME()
{
firstName = "John";
lastName = "Doe";
}

public NAME(String first, String last)
{
firstName = first;
lastName = last;
}
}


You just have to have every variable situation declared so that the compiler knows to tell the program how much memory to reserve when it is running.

Hope this helps! biggrin.gif

This post has been edited by Locke37: 10 Nov, 2008 - 07:25 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 02:50PM

Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month