File tree 4 files changed +23
-16
lines changed
4 files changed +23
-16
lines changed Original file line number Diff line number Diff line change @@ -62,14 +62,11 @@ Checkstyle configuration for Think Java, 2nd Edition.
62
62
63
63
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
64
64
<module name =" AtclauseOrder" />
65
- <module name =" JavadocMethod" />
66
- <module name =" JavadocStyle" />
67
- <module name =" JavadocType" >
68
65
<!--
69
- <property name="authorFormat" value="\S"/>
70
- <property name="versionFormat" value="\S"/>
66
+ <module name="JavadocMethod"/>
71
67
-->
72
- </module >
68
+ <module name =" JavadocStyle" />
69
+ <module name =" JavadocType" />
73
70
<module name =" NonEmptyAtclauseDescription" />
74
71
75
72
<!-- See http://checkstyle.sf.net/config_misc.html -->
Original file line number Diff line number Diff line change 1
- import java .util .Arrays ;
2
1
import java .util .Random ;
3
2
4
3
/**
5
4
* A deck of playing cards (of fixed length).
6
5
*/
7
6
public class Deck {
8
7
8
+ // This is a class variable so we don't have to create
9
+ // a new Random object every time we call randomInt.
10
+ private static Random random = new Random ();
11
+
9
12
private Card [] cards ;
10
13
11
14
/**
@@ -49,7 +52,7 @@ public void print() {
49
52
* Returns a string representation of the deck.
50
53
*/
51
54
public String toString () {
52
- return Arrays . toString ( this . cards ) ;
55
+ return "TODO" ;
53
56
}
54
57
55
58
/**
@@ -122,4 +125,11 @@ public Deck mergeSort() {
122
125
*/
123
126
public void insertionSort () {
124
127
}
128
+
129
+ /**
130
+ * Helper method for insertion sort.
131
+ */
132
+ private void insert (Card card , int i ) {
133
+ }
134
+
125
135
}
Original file line number Diff line number Diff line change @@ -31,17 +31,17 @@ public void addDeck(Deck deck) {
31
31
}
32
32
33
33
/**
34
- * Removes a card from the top of the pile .
34
+ * Returns true if this pile has no cards .
35
35
*/
36
- public Card popCard () {
37
- return this .cards .remove ( 0 );
36
+ public boolean isEmpty () {
37
+ return this .cards .isEmpty ( );
38
38
}
39
39
40
40
/**
41
- * Returns the number of cards in the pile.
41
+ * Removes a card from the top of the pile.
42
42
*/
43
- public int size () {
44
- return this .cards .size ( );
43
+ public Card popCard () {
44
+ return this .cards .remove ( 0 );
45
45
}
46
46
47
47
}
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ public static void main(String[] args) {
16
16
p2 .addDeck (deck .subdeck (26 , 51 ));
17
17
18
18
// while both piles are not empty
19
- while (p1 .size () > 0 && p2 .size () > 0 ) {
19
+ while (! p1 .isEmpty () && ! p2 .isEmpty () ) {
20
20
Card c1 = p1 .popCard ();
21
21
Card c2 = p2 .popCard ();
22
22
@@ -34,7 +34,7 @@ public static void main(String[] args) {
34
34
}
35
35
36
36
// display the winner
37
- if (p1 . size () > 0 ) {
37
+ if (p2 . isEmpty () ) {
38
38
System .out .println ("Player 1 wins!" );
39
39
} else {
40
40
System .out .println ("Player 2 wins!" );
You can’t perform that action at this time.
0 commit comments