File tree Expand file tree Collapse file tree 4 files changed +23
-16
lines changed Open diff view settings
Expand file tree Collapse file tree 4 files changed +23
-16
lines changed Open diff view settings
Original file line number Diff line number Diff line change @@ -62,14 +62,11 @@ Checkstyle configuration for Think Java, 2nd Edition.
6262
6363 <!-- See http://checkstyle.sf.net/config_javadoc.html -->
6464 <module name =" AtclauseOrder" />
65- <module name =" JavadocMethod" />
66- <module name =" JavadocStyle" />
67- <module name =" JavadocType" >
6865<!--
69- <property name="authorFormat" value="\S"/>
70- <property name="versionFormat" value="\S"/>
66+ <module name="JavadocMethod"/>
7167-->
72- </module >
68+ <module name =" JavadocStyle" />
69+ <module name =" JavadocType" />
7370 <module name =" NonEmptyAtclauseDescription" />
7471
7572 <!-- See http://checkstyle.sf.net/config_misc.html -->
Original file line number Diff line number Diff line change 1- import java .util .Arrays ;
21import java .util .Random ;
32
43/**
54 * A deck of playing cards (of fixed length).
65 */
76public class Deck {
87
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+
912 private Card [] cards ;
1013
1114 /**
@@ -49,7 +52,7 @@ public void print() {
4952 * Returns a string representation of the deck.
5053 */
5154 public String toString () {
52- return Arrays . toString ( this . cards ) ;
55+ return "TODO" ;
5356 }
5457
5558 /**
@@ -122,4 +125,11 @@ public Deck mergeSort() {
122125 */
123126 public void insertionSort () {
124127 }
128+
129+ /**
130+ * Helper method for insertion sort.
131+ */
132+ private void insert (Card card , int i ) {
133+ }
134+
125135}
Original file line number Diff line number Diff line change @@ -31,17 +31,17 @@ public void addDeck(Deck deck) {
3131 }
3232
3333 /**
34- * Removes a card from the top of the pile .
34+ * Returns true if this pile has no cards .
3535 */
36- public Card popCard () {
37- return this .cards .remove ( 0 );
36+ public boolean isEmpty () {
37+ return this .cards .isEmpty ( );
3838 }
3939
4040 /**
41- * Returns the number of cards in the pile.
41+ * Removes a card from the top of the pile.
4242 */
43- public int size () {
44- return this .cards .size ( );
43+ public Card popCard () {
44+ return this .cards .remove ( 0 );
4545 }
4646
4747}
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ public static void main(String[] args) {
1616 p2 .addDeck (deck .subdeck (26 , 51 ));
1717
1818 // while both piles are not empty
19- while (p1 .size () > 0 && p2 .size () > 0 ) {
19+ while (! p1 .isEmpty () && ! p2 .isEmpty () ) {
2020 Card c1 = p1 .popCard ();
2121 Card c2 = p2 .popCard ();
2222
@@ -34,7 +34,7 @@ public static void main(String[] args) {
3434 }
3535
3636 // display the winner
37- if (p1 . size () > 0 ) {
37+ if (p2 . isEmpty () ) {
3838 System .out .println ("Player 1 wins!" );
3939 } else {
4040 System .out .println ("Player 2 wins!" );
You can’t perform that action at this time.
0 commit comments