Skip to content

Commit ede1af8

Browse files
committed
fixed commonets on code in chapter 9 and removed line numbers. issue RunestoneInteractive#19
1 parent a9487c3 commit ede1af8

1 file changed

Lines changed: 43 additions & 39 deletions

File tree

‎source/ch_9_commonmistakes.ptx‎

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,21 @@
1515
</p>
1616
<program language="java" interactive="activecode" line-numbers="yes">
1717
<code>
18-
import java.util.ArrayList; // Line 1: Import necessary class
18+
import java.util.ArrayList; // Import necessary class
1919

20-
public class Main { // Line 3: Class declaration
21-
public static void main(String[] args) { // Line 4: Main method declaration
22-
23-
count = new ArrayList&lt;Integer&lt;(10); // Line 6: Attempt to use 'count' without declaration
20+
public class Main { // Class declaration
21+
22+
// Main method declaration
23+
public static void main(String[] args) {
2424

25-
System.out.println("ArrayList created."); // Line 8: This line won't be reached due to the error.
25+
// Attempt to use 'count' without declaration
26+
count = new ArrayList&lt;Integer&lt;(10);
2627

27-
} // Line 10: End of main method
28-
} // Line 11: End of class
28+
// This line won't be reached due to the error.
29+
System.out.println("ArrayList created.");
30+
31+
} // End of main method
32+
} // End of class
2933
</code>
3034
</program>
3135
<p>
@@ -42,14 +46,14 @@
4246
</p>
4347
<code>
4448
// Histo.java
45-
public class Histo { // Line 2: Class declaration
49+
public class Histo { // Class declaration
4650

47-
public static void main(String[] args) { // Line 4: Main method declaration
48-
49-
Scanner data = null; // Line 6: This line will cause the "cannot find symbol" error
51+
public static void main(String[] args) { // Main method declaration
52+
// This line will cause the "cannot find symbol" error
53+
Scanner data = null;
5054

51-
} // Line 8: End of main method
52-
} // Line 9: End of class
55+
} // End of main method
56+
} // End of class
5357
</code>
5458
</program>
5559
<p>
@@ -65,18 +69,18 @@
6569
</p>
6670
<program language="java" interactive="activecode" line-numbers="yes">
6771
<code>
68-
// Histo.java // Line 1: The filename for this example
69-
import java.io.File; // Line 2: Import the File class, needed for file operations
70-
import java.util.Scanner; // Line 3: Import the Scanner class, now correctly imported
72+
// Histo.java // The filename for this example
73+
import java.io.File; // Import the File class, needed for file operations
74+
import java.util.Scanner; // Import the Scanner class, now correctly imported
7175

72-
public class Histo { // Line 5: Class declaration
76+
public class Histo { // Class declaration
7377

74-
public static void main(String[] args) { // Line 7: Main method declaration
78+
public static void main(String[] args) { // Main method declaration
7579

76-
Scanner data = Scanner(new File("test.dat")); // Line 9: This Line will cause an error
80+
Scanner data = Scanner(new File("test.dat")); // This Line will cause an error
7781

78-
} // Line 12: End of main method
79-
} // Line 13: End of class
82+
} // End of main method
83+
} // End of class
8084
</code>
8185
</program>
8286
<p>
@@ -99,15 +103,15 @@
99103
<program language="java" interactive="activecode" line-numbers="yes">
100104
<code>
101105
// Histo.java
102-
import java.util.Scanner; // Line 1
103-
// Line 2
104-
public class Histo { // Line 3
105-
// Line 4
106-
public static void main(String[] args) { // Line 5
107-
Scanner data = null // Line 7: The error will point here
108-
System.out.println("This line will not compile."); // Line 8
109-
}
110-
}
106+
import java.util.Scanner; // Imports Scanner
107+
108+
public class Histo { // Class declaration
109+
110+
public static void main(String[] args) { // Main method declaration
111+
Scanner data = null // The error will point here
112+
System.out.println("This line will not compile.");
113+
}// End of main method
114+
}//End of class
111115
</code>
112116
</program>
113117
<p>
@@ -124,20 +128,20 @@
124128
<program language="java" interactive="activecode" line-numbers="yes">
125129
<code>
126130
// UncheckedWarningDemo.java
127-
import java.util.ArrayList; // Line 2: Import the ArrayList class
131+
import java.util.ArrayList; // Import the ArrayList class
128132

129-
public class UncheckedWarningDemo { // Line 4: Class declaration
133+
public class UncheckedWarningDemo { // Class declaration
130134

131-
public static void main(String[] args) { // Line 6: Main method declaration
135+
public static void main(String[] args) { // Main method declaration
132136

133137
// This is where the potential for unchecked operations begins.
134-
ArrayList rawList = new ArrayList();//Line 9
135-
136-
rawList.add("Hello");//Line 11: This is the line that will throw an error
138+
ArrayList rawList = new ArrayList();
137139

140+
rawList.add("Hello");
141+
//This is the line that will throw an error
138142
System.out.println("Element added: " + rawList.get(0));
139-
} // Line 14: End of main method
140-
} // Line 15: End of class
143+
} // End of main method
144+
} // End of class
141145
</code>
142146
</program>
143147
<p>

0 commit comments

Comments
 (0)