Results 1 to 14 of 14
  1. #1
    adjit is offline Senior Member
    Join Date
    Mar 2011
    Posts
    171
    Rep Power
    0

    Default 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 09:37 PM. Reason: the coloring didn't work.

  2. #2
    jonstewart is offline Member
    Join Date
    Apr 2011
    Posts
    7
    Rep Power
    0

    Default

    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 09:45 PM.

  3. #3
    adjit is offline Senior Member
    Join Date
    Mar 2011
    Posts
    171
    Rep Power
    0

    Default

    hahaha yes I am, but my display method keeps giving me an error of missing method body, or declare abstract

  4. #4
    Iron Lion is offline Senior Member
    Join Date
    Nov 2010
    Posts
    210
    Rep Power
    5

    Default

    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.

  5. #5
    jonstewart is offline Member
    Join Date
    Apr 2011
    Posts
    7
    Rep Power
    0

    Default

    Quote Originally Posted by Iron Lion View Post
    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.
    Yeah the assignment says "This class will have 3 fields:
    A String variable called suit
    An integer called value
    A Picture variable called face"

  6. #6
    adjit is offline Senior Member
    Join Date
    Mar 2011
    Posts
    171
    Rep Power
    0

    Default

    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
    }

  7. #7
    Iron Lion is offline Senior Member
    Join Date
    Nov 2010
    Posts
    210
    Rep Power
    5

    Default

    It would help if you post the code for your Picture class.

  8. #8
    adjit is offline Senior Member
    Join Date
    Mar 2011
    Posts
    171
    Rep Power
    0

    Default

    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.

  9. #9
    Iron Lion is offline Senior Member
    Join Date
    Nov 2010
    Posts
    210
    Rep Power
    5

    Default

    this.show() doesn't work because your Card class doesn't have a show() method. Instead, call face.show().

  10. #10
    adjit is offline Senior Member
    Join Date
    Mar 2011
    Posts
    171
    Rep Power
    0

    Default

    so I have that part down, I just need the getSuit() method. That is where I am getting the majority of my problems.

  11. #11
    Iron Lion is offline Senior Member
    Join Date
    Nov 2010
    Posts
    210
    Rep Power
    5

    Default

    Java Code:
    public String getSuit();
    {
    return suit;
    }
    Get rid of the semicolon after the method declaration.

  12. #12
    adjit is offline Senior Member
    Join Date
    Mar 2011
    Posts
    171
    Rep Power
    0

    Default

    god I'm a retard... thanks so much!!

  13. #13
    Iron Lion is offline Senior Member
    Join Date
    Nov 2010
    Posts
    210
    Rep Power
    5

    Default

    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:

    Java Code:
    public String getSuit() {
    ...
    }
    Of course, if your tutor insists on you placing your braces the other way, there's not much you can do about it.

  14. #14
    adjit is offline Senior Member
    Join Date
    Mar 2011
    Posts
    171
    Rep Power
    0

    Default

    yeah, I just feel like it makes it look more crowded and stuff, so its just personal preferences. Would you mind if I added you in case I get any more easy problems?

Similar Threads

  1. Help with creating a deck of cards
    By Carouselification in forum New To Java
    Replies: 5
    Last Post: 03-06-2011, 05:45 AM
  2. Deck of cards problem
    By VelvetMirror in forum New To Java
    Replies: 2
    Last Post: 02-16-2011, 09:02 PM
  3. Creating a deck of cards and printing in console
    By Danieldcc in forum New To Java
    Replies: 7
    Last Post: 10-12-2010, 08:37 AM
  4. Deck of Cards
    By khunmato in forum New To Java
    Replies: 13
    Last Post: 09-06-2009, 06:47 PM
  5. creating a deck of cards using a linked list
    By boomba88 in forum New To Java
    Replies: 2
    Last Post: 09-11-2008, 04:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •