Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b98cbcd

Browse filesBrowse files
committed
ch13 revisions
1 parent 3e9b0a3 commit b98cbcd
Copy full SHA for b98cbcd

File tree

Expand file treeCollapse file tree

4 files changed

+23
-16
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+23
-16
lines changed
Open diff view settings
Collapse file

‎Checkstyle.xml‎

Copy file name to clipboardExpand all lines: Checkstyle.xml
+3-6Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff 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 -->
Collapse file

‎ch13/Deck.java‎

Copy file name to clipboardExpand all lines: ch13/Deck.java
+12-2Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import java.util.Arrays;
21
import java.util.Random;
32

43
/**
54
* A deck of playing cards (of fixed length).
65
*/
76
public 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
}
Collapse file

‎ch13/Pile.java‎

Copy file name to clipboardExpand all lines: ch13/Pile.java
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff 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
}
Collapse file

‎ch13/War.java‎

Copy file name to clipboardExpand all lines: ch13/War.java
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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!");

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.