• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Inheritance

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm constructing a StandardDeck class that inherits from a Card class. I've compiled my code and am receiving the error "Card(int,int) in Card cannot be applied to()." Does anyone know what this means? Here is my code for the StandardDeck class:



Thanks!
 
Amy Lee
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If anyone could help me with this, I would REALLY appreciate it - let me know if I need to give more information. THANKS!
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It means that Card has only one constructor, and it takes two ints as arguments, yet StandardDeck's constructor doesn't arrange to call it. You'd do this using a call like:

super(intx, inty);

Alternatively, you could add a no-argument "default" constructor to Card; this is the one that StandardDeck calls implicitly.

Now, I have to point out that a Deck isn't a kind of Card, and it seems to me that you've already got many Deck-like features in your Card class, so you need to give some serious thought as to whether having Deck inherit from Card makes any sense (hint: it doesn't!)
 
Amy Lee
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your feedback - I thought the same thing when I extended Card, but I wasn't sure if I was correct. My teacher gave us an assignment and he provided a Card class for us to use, yet he wants us to create a StandardDeck class (and a Hand class). I automatically thought "extend Card," but I see that I'm wrong.

How can I call methods from the Card class without extending it to StandardDeck?
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A Deck would presumably own a collection of Card objects, and similarly a hand might also be a (smaller) collection of Cards. A function that scores a hand might look like the following: it adds up the values of each card by calling getValue() on each Card object in the collection. The variable "card" refers to each card in the hand in turn, and this code uses that variable to call Card's methods.

[URL]
public int score(List hand) {
int score = 0;
for (Iterator it = hand.iterator(); it.hasNext() {
Card card = (Card) it.next();
score += card.getValue();
}
return score;
}
[/code]
 
Amy Lee
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.
 
Destiny's powerful hand has made the bed of my future. And this tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic