Results 1 to 14 of 14
- 04-06-2011, 08:37 PM #1
Senior Member
- Join Date
- Mar 2011
- Posts
- 171
- Rep Power
- 0
Creating a card class for a Deck of cards
So I have my code below, and for getSuit() I keep getting an error saying that the return value is outside the method, which I don't get. Also my display() method is completely wrong... I just don't know how to go about fixing it.
Also, the methods just have to return either the values of what was input into public Card()
public class Card
{
private String suit;
int value;
private Picture face;
public Card(Picture f, String s, int v)
{
suit = s;
value = v;
face = f;
}
public int getValue()
{
return value;
}
public String getSuit();
{
return suit;
}
public Picture display();
{
face.show();
}Last edited by adjit; 04-06-2011 at 08:37 PM. Reason: the coloring didn't work.
- 04-06-2011, 08:42 PM #2
Member
- Join Date
- Apr 2011
- Posts
- 7
- Rep Power
- 0
hah, this looks too familiar..im gonna assume you're taking the csi201 class at ualbany? xD since i'm also struggling with this assignment, i think your display() method is fine, because that's what i have as well...
Last edited by jonstewart; 04-06-2011 at 08:45 PM.
- 04-06-2011, 08:55 PM #3
Senior Member
- Join Date
- Mar 2011
- Posts
- 171
- Rep Power
- 0
hahaha yes I am, but my display method keeps giving me an error of missing method body, or declare abstract
- 04-06-2011, 09:52 PM #4
Senior Member
- Join Date
- Nov 2010
- Posts
- 210
- Rep Power
- 3
Is it a requirement of the assignment that you use String for suit and int for rank? If not, consider using enums.
Your display() method is failing because its return type is Picture, but there's no return statement in the method.
- 04-06-2011, 09:59 PM #5
Member
- Join Date
- Apr 2011
- Posts
- 7
- Rep Power
- 0
- 04-06-2011, 09:59 PM #6
Senior Member
- Join Date
- Mar 2011
- Posts
- 171
- Rep Power
- 0
Our class has not yet discussed enums, so I am assuming we cannot use them.
Our class's need to have 3 fields:
• A String variable called suit
• An integer called value
• A Picture variable called face
so for my picture class would it be
public void display()
{
this.show() // it is calling a method from a different class called show() but idk if this is right because I still got the error
}
- 04-06-2011, 10:03 PM #7
Senior Member
- Join Date
- Nov 2010
- Posts
- 210
- Rep Power
- 3
It would help if you post the code for your Picture class.
- 04-06-2011, 10:04 PM #8
Senior Member
- Join Date
- Mar 2011
- Posts
- 171
- Rep Power
- 0
the show() method is public.
display()
This method will take no parameters and will return nothing. It will utilize the show() method in
the Picture class to display the card’s face image to the user.
- 04-06-2011, 10:07 PM #9
Senior Member
- Join Date
- Nov 2010
- Posts
- 210
- Rep Power
- 3
this.show() doesn't work because your Card class doesn't have a show() method. Instead, call face.show().
- 04-06-2011, 10:09 PM #10
Senior Member
- Join Date
- Mar 2011
- Posts
- 171
- Rep Power
- 0
so I have that part down, I just need the getSuit() method. That is where I am getting the majority of my problems.
- 04-06-2011, 10:11 PM #11
Senior Member
- Join Date
- Nov 2010
- Posts
- 210
- Rep Power
- 3
Get rid of the semicolon after the method declaration.Java Code:public String getSuit(); { return suit; }
- 04-06-2011, 10:13 PM #12
Senior Member
- Join Date
- Mar 2011
- Posts
- 171
- Rep Power
- 0
god I'm a retard... thanks so much!!
- 04-06-2011, 10:15 PM #13
Senior Member
- Join Date
- Nov 2010
- Posts
- 210
- Rep Power
- 3
Easy mistake to make. It's less likely to catch you out if you put your opening brace on the same line as the declaration, like so:
Of course, if your tutor insists on you placing your braces the other way, there's not much you can do about it.Java Code:public String getSuit() { ... }
- 04-06-2011, 10:20 PM #14
Senior Member
- Join Date
- Mar 2011
- Posts
- 171
- Rep Power
- 0
Similar Threads
-
Help with creating a deck of cards
By Carouselification in forum New To JavaReplies: 5Last Post: 03-06-2011, 04:45 AM -
Deck of cards problem
By VelvetMirror in forum New To JavaReplies: 2Last Post: 02-16-2011, 08:02 PM -
Creating a deck of cards and printing in console
By Danieldcc in forum New To JavaReplies: 7Last Post: 10-12-2010, 07:37 AM -
Deck of Cards
By khunmato in forum New To JavaReplies: 13Last Post: 09-06-2009, 05:47 PM -
creating a deck of cards using a linked list
By boomba88 in forum New To JavaReplies: 2Last Post: 09-11-2008, 03:34 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks