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 44526cc

Browse filesBrowse files
committed
appendix revisions
1 parent 4e05ec0 commit 44526cc
Copy full SHA for 44526cc

File tree

Expand file treeCollapse file tree

6 files changed

+24
-18
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

6 files changed

+24
-18
lines changed
Open diff view settings
Collapse file

‎Checkstyle.xml‎

Copy file name to clipboardExpand all lines: Checkstyle.xml
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ Checkstyle configuration for Think Java, 2nd Edition.
3434
<module name="FallThrough"/>
3535
<module name="InnerAssignment"/>
3636
<module name="ModifiedControlVariable"/>
37-
<module name="MultipleVariableDeclarations"/>
3837
<module name="OneStatementPerLine"/>
3938
<module name="ParameterAssignment"/>
4039
<module name="RequireThis">
@@ -62,7 +61,6 @@ Checkstyle configuration for Think Java, 2nd Edition.
6261
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
6362
<module name="AtclauseOrder"/>
6463
<module name="JavadocStyle"/>
65-
<module name="JavadocType"/>
6664
<module name="NonEmptyAtclauseDescription"/>
6765

6866
<!-- See http://checkstyle.sf.net/config_misc.html -->
Collapse file

‎appb/Convert.java‎

Copy file name to clipboardExpand all lines: appb/Convert.java
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017 Allen Downey and Chris Mayfield
2+
* Copyright (c) 2019 Allen Downey and Chris Mayfield
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -23,7 +23,7 @@
2323
import java.util.Scanner;
2424

2525
/**
26-
* Utility class for converting to/from the metric system.
26+
* Methods for converting to/from the metric system.
2727
*
2828
* @author Allen Downey
2929
* @author Chris Mayfield
Collapse file

‎appb/DigitUtil.java‎

Copy file name to clipboardExpand all lines: appb/DigitUtil.java
+4-8Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,16 @@ public class DigitUtil {
1313
* @return true if x has one digit, false otherwise
1414
*/
1515
public static boolean isSingleDigit(int x) {
16-
if (x > -10 && x < 10) {
17-
return true;
18-
} else {
19-
return false;
20-
}
21-
}
22-
23-
public static boolean isSingleDigit2(int x) {
2416
return x > -10 && x < 10;
2517
}
2618

2719
public static void main(String[] args) {
2820
System.out.println(isSingleDigit(2));
21+
2922
boolean bigFlag = !isSingleDigit(17);
23+
if (bigFlag) {
24+
System.out.println("not single");
25+
}
3026

3127
int z = 9;
3228
if (isSingleDigit(z)) {
Collapse file

‎appc/Mickey.java‎

Copy file name to clipboardExpand all lines: appc/Mickey.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static void main(String[] args) {
1111
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
1212
Canvas canvas = new Mickey();
1313
canvas.setSize(400, 400);
14-
canvas.setBackground(Color.white);
14+
canvas.setBackground(Color.WHITE);
1515
frame.add(canvas);
1616
frame.pack();
1717
frame.setVisible(true);
Collapse file

‎appc/Moire.java‎

Copy file name to clipboardExpand all lines: appc/Moire.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static void main(String[] args) {
1010
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
1111
Canvas canvas = new Moire();
1212
canvas.setSize(400, 400);
13-
canvas.setBackground(Color.white);
13+
canvas.setBackground(Color.WHITE);
1414
frame.add(canvas);
1515
frame.pack();
1616
frame.setVisible(true);
Collapse file

‎appd/Complex.java‎

Copy file name to clipboard
+16-4Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import java.awt.Rectangle;
22

33
/**
4-
* Example from "My method doesn't return what I expect."
4+
* Examples from Logic Errors section.
55
*/
66
public class Complex {
77

8+
/**
9+
* My method doesn't return what I expect.
10+
*/
811
public static Rectangle intersection(Rectangle a, Rectangle b) {
912
int x1 = Math.min(a.x, b.x);
1013
int y1 = Math.min(a.y, b.y);
@@ -14,10 +17,19 @@ public static Rectangle intersection(Rectangle a, Rectangle b) {
1417
return rect;
1518
}
1619

20+
/**
21+
* I've got a big, hairy expression and it doesn’t do what I expect.
22+
*/
1723
public static void main(String[] args) {
18-
Rectangle x = new Rectangle(0, 0, 10, 10);
19-
Rectangle y = new Rectangle(-5, -5, -5, -5);
20-
System.out.println(intersection(x, y));
24+
Rectangle rect = new Rectangle(0, 0, 10, 10);
25+
Rectangle ngle = new Rectangle(-5, -5, -5, -5);
26+
System.out.println(intersection(rect, ngle));
27+
28+
double halfWidth = 0.5 * rect.getWidth();
29+
double halfHeight = 0.5 * rect.getHeight();
30+
int dx = (int) Math.round(halfWidth);
31+
int dy = (int) Math.round(halfHeight);
32+
rect.translate(dx, dy);
2133
}
2234

2335
}

0 commit comments

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