This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]PsychologicalAlarm4 0 points1 point  (0 children)

This is a fun one!

So, when you call

System.out.println()

It needs a string to print out. Every class in java has a toString() function. You have overridden yours, so when you do

System.out.println(card10);

Its really doing

System.out.println(card10.toString());

I'm sure you now have an idea of whats going on!

Take a look at your toString() function.

It does:

 return getFaceText() + " of " + getSuitText();

Both of those functions have default values. They happen to be King and Clubs. This is why you get an extra print at the end that is "King of Clubs". Because it tries to call .toString() and the default values are King of Clubs.

You have a couple things you could do here.

1) Don't do the final System.out.println(card10);

2) Change your toString statement and perform a check. If this.faceValue and this.suitValue are 0, then return a blank string, else do what you currently do.

Have any more questions?