week 8 ex15 sortedCards

68 views
Skip to first unread message

csabaf...@gmail.com

unread,
Jan 20, 2015, 11:22:36 AM1/20/15
to moo...@googlegroups.com
Hi,

I'm having problems with week 8 exercise 15: sortedCards. During the test I got an error, shown in my paste bin link. Expcted output was <1> received <0>. I ran the code several times with the test input and I always received <1> as an output. What could be the problem?


Kiitos avustanne (Google translat, hope that's right :))


Best regards


Supported languages are English and Finnish

Please use our build in TMC Pastebin when asking questions related to your code  
 
TMC Plugin has built-in code sharing feature. 
In NetBeans, select TMC -> Send code to TMC pastebin. Copy the link you receive and paste it to your message.  

You may use our web interface to share code snippets: http://paste.mooc.fi

Joni

unread,
Jan 21, 2015, 1:08:25 AM1/21/15
to moo...@googlegroups.com, csabaf...@gmail.com
Hi,

You seem to have found a bug in our tests, which I have just fixed.

Your NetBeans should propose an update, if not you can download it manually from TMC-menu in NetBeans. Or you could just run tests on the server.

Correct test output is:

B_HandTest comparingWorks3

Hand hand1 = new Hand();
hand1
.add( new Card(12,Card.HEARTS) );
Hand hand2 = new Hand();
hand2
.add( new Card(3,Card.CLUBS) );
hand2
.add( new Card(9,Card.CLUBS) );
hand2
.compareTo(hand1)
 expected
: <0> but was: <1>

Sorry for your trouble.

BR
Joni

csabaf...@gmail.com

unread,
Jan 21, 2015, 9:03:50 AM1/21/15
to moo...@googlegroups.com, csabaf...@gmail.com
Hi Joni,

Thank you for your reply. I'm afraid there is a mistake now in your test input. If the expected output is <0> then the two hands should be equal. 'hand1' in the test contains a Q Clubs and 'hand2' to consists of 3 Clubs and 9 Clubs. The value of 'hand1' is 12(Q) + 3(suit value of Clubs) = 15, the value of 'hand2' is 3 + 9 + 3(Clubs) + 3(Clubs) = 18. So the value of 'hand2' is greater than the value of 'hand1'.
I think one of the cards in the second hand should be changed to Spades suit of which value is 0, so the two hands will be equal.

Regards,

Csaba

Joni

unread,
Jan 21, 2015, 9:59:43 AM1/21/15
to moo...@googlegroups.com, csabaf...@gmail.com
Hi,

Assignment can be somehow confusing since it states 

COMPARING HANDS
In one card game, the most valuable hand, where the sum of the cards value is the biggest. Modify the class Hand so that it could be compared according to this criterion

Earlier it has been stated that Cards have got a value and a suit. So Hand comparison should not take in account cards suits.

BR
Joni

csabaf...@gmail.com

unread,
Jan 21, 2015, 10:37:34 AM1/21/15
to moo...@googlegroups.com, csabaf...@gmail.com
Thank you Joni, I just removed the section of the hand.compareTo() method that compared hands based on their suits and it worked fine now.
Regards,
Csaba
Reply all
Reply to author
Forward
0 new messages