First post on here so firstly hello all!
I am looking into making a card guessing game. Having 5 chances to guess the correct card
I want the user to be able to select one of 2 options either
1. Guess a card
with the guess a card i want them to be able to type in either S,D,C,H for the suits and 2,3,4,5,6,7,8,9,10,J,Q,K,A for the suit so when it comes up it says Guess a card and the user would input 2H for the 2 of hearts
if incorrect then the user would be told incorrect guess you have 4 guesses remaining. I have got the inputreader which i think i will need and i have tried to write the card class but i have struggled writing it. Below is the input reader
If anyone has any help or tips they can give me towards writing the card class and if required any others then it would be greatly appreciated!
Those methods and fields of the reading class could beneficially be declared static, as long as you are not calling them from several threads.
Write down what you think a Card class ought to look like . . .
And welcome to the Ranch
Joined: Jul 29, 2010
Sorry it has taken me a while to reply.
I attempted a card class but i don't know how good it is.
It's admirable that you're working on such a detailed class to model a card. But is that necessary for your purposes? One way to look at the game you described is guessing a value from 0 through 51.
But beyond questioning whether you need it, some feedback on the class would be:
The methods getValueName and getSuitName calculate and assign these variables every time the method is called. You could do this once in the constructor (if needed). Also, a switch statement might be more straight forward than multiple else if's. (Remember, chars can be used in a switch.)
Consider implementing Comparable, so that Card instances can be easily compared and ordered.
Consider overriding methods toString, equals, and hashCode.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org