• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Beginner : Seeking some help/ideas on basic solitaire card game

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi! I am beginner in java and looking for some help and ideas in developing basic solitaire game. To start-with , I am trying to implement just one class and it's methods at the moment and below is attached code and snapshot of what I tried. please suggest where and what sort of changes I need to make ? Thanks in advance!!

Class : Card

Fields:
cardIndex: The card's index, from 1 to 52.

Methods:
getSuit: Returns the card's suit.
getValue: Returns the card's value (such as 10, king, etc).
colour: The colour of the card is `red' if this card is a heart or diamond, and `black' otherwise.

toString: Returns a string representation of this card, including its suit and rank. Example: Ace of clubs would be ClubA, ten of diamonds would be Diamond10, and queen of spades would be SpadeQ.

paintThis(Graphics g) Draws the card. In the simple GUI, this should draw a Rectangle, with the string representation of the card written in the colour corre-sponding to the colour of the card (either black or red)

 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good start. A few suggestions:

* Use a Enum to represent the card's suit SPADE,HEART,CLUB,DIAMOND
* The Card class should be a POJO, put the main method in a new class
* The card's value (eg A,2,3 etc) may probably be a Enum too, rather than an array
* If you want to associate a card's color, use the java.awt.Color class
 
reply
    Bookmark Topic Watch Topic
  • New Topic