Skip to content

Commit ba86e59

Browse files
authored
Merge pull request #169 from RunestoneInteractive/fix-xml-ids
Fix xml ids
2 parents ba6a835 + b93f714 commit ba86e59

6 files changed

Lines changed: 93 additions & 93 deletions

source/ch2_firstjavaprogram.ptx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
The best way to understand classes and objects is to see them in action. Let's define a <c>Dog</c> class in Python:
3131
</p>
3232

33-
<program language="python" xml:id="python-class-example">
33+
<program xml:id="python-class-example" language="python">
3434
<code>
3535
class Dog:
3636
def __init__(self, name, breed, fur_color):

source/ch3_javadatatypes.ptx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
</p>
9696

9797

98-
<program interactive="activecode" language="python">
98+
<program xml:id="python-temperature-conversion" interactive="activecode" language="python">
9999
<code>
100100
def main():
101101
fahr = int(input("Enter the temperature in F: "))
@@ -110,7 +110,7 @@ main()
110110
</p>
111111

112112

113-
<program interactive="activecode" language="java">
113+
<program xml:id="java-temperature-conversion" interactive="activecode" language="java">
114114
<code>
115115
import java.util.Scanner;
116116
public class TempConv {
@@ -431,7 +431,7 @@ if (myAnimal instanceof Dog) {
431431
</p>
432432

433433

434-
<program interactive="activecode" language="python">
434+
<program xml:id="python-input-file1" interactive="activecode" language="python">
435435
<code>
436436
def main():
437437
count = [0]*10
@@ -528,7 +528,7 @@ Here is the Java code needed to write the exact same program:
528528
</p>
529529
</note>
530530

531-
<program interactive="activecode" language="java" datafile="test.dat">
531+
<program xml:id="java-null-object" interactive="activecode" language="java" datafile="test.dat">
532532
<code>
533533
import java.util.Scanner;
534534
import java.util.ArrayList;
@@ -655,11 +655,11 @@ public class Histo {
655655
<title>Arrays</title>
656656

657657
<p>
658-
As I said at the outset of this section, we are going to use Java <c>ArrayLists</c> because they are easier to use and more closely match the way that Python lists behave. However, if you look at Java code on the internet or even in your Core Java books you are going to see examples of something called arrays. In fact you have already seen one example of an array declared in the &#x2018;Hello World&#x2019; program. Lets rewrite this program to use primitive arrays rather than array lists.
658+
As was said at the outset of this section, we are going to use Java <c>ArrayLists</c> because they are easier to use and more closely match the way that Python lists behave. However, if you look at Java code on the internet or even in your core Java books you are going to see examples of something called an array. In fact, you have already seen one example of an array declared in the &#x2018;Hello World&#x2019; program. Let's rewrite this program to use primitive arrays rather than array lists.
659659
</p>
660660

661661

662-
<program interactive="activecode" language="java" datafile="test.dat">
662+
<program xml:id="java-array" interactive="activecode" language="java" datafile="test.dat">
663663
<code>
664664
import java.util.Scanner;
665665
import java.io.File;
@@ -708,7 +708,7 @@ public class HistoArray {
708708
</p>
709709

710710

711-
<program interactive="activecode" language="python">
711+
<program xml:id="python-input-file2" interactive="activecode" language="python">
712712
<code>
713713
def main():
714714
data = open('alice30.txt')
@@ -755,7 +755,7 @@ main()
755755
</p>
756756

757757

758-
<program interactive="activecode" language="java" datafile="alice30.txt">
758+
<program xml:id="java-use-input-file" interactive="activecode" language="java" datafile="alice30.txt">
759759
<code>
760760
import java.util.Scanner;
761761
import java.util.ArrayList;

source/ch4_conditionals.ptx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
In Python the simple <c>if</c> statement is written as:
1717
</p>
1818

19-
<program interactive="activecode" language="python">
19+
<program xml:id="python-simple-if" interactive="activecode" language="python">
2020
<code>
2121
score = 95
2222
if score &gt;= 90:
@@ -26,7 +26,7 @@ if score &gt;= 90:
2626
<p>
2727
In Java, this same pattern requires two changes: the condition must be in parentheses <c>()</c>, and the code block must be enclosed in curly braces <c>{}</c>.
2828
</p>
29-
<program interactive="activecode" language="java">
29+
<program xml:id="java-simple-if" interactive="activecode" language="java">
3030
<code>
3131
public class SimpleIfExample {
3232
public static void main(String[] args) {
@@ -40,15 +40,15 @@ if score &gt;= 90:
4040
</program>
4141
<p>
4242
Once again you can see that in Java the curly braces define a block rather than indentation.
43-
In Java the parenthesis around the condition are required because it is technically a function that evaluates to <c>True</c> or <c>False</c>.
43+
In Java, the parentheses around the condition are required because it is technically a function that evaluates to <c>True</c> or <c>False</c>.
4444
</p>
4545
</section>
4646

47-
<section xml:id="if-else">
47+
<section xml:id="use-the-if-else-statement">
4848
<title>Using the <c>if</c> - <c>else</c> Statement</title>
4949

5050
<p>The Java equivalent follows the same syntactical rules as before.</p>
51-
<program interactive="activecode" language="python">
51+
<program xml:id="python-if-else" interactive="activecode" language="python">
5252
<code>
5353
age = 16
5454
if age &gt;= 18:
@@ -58,7 +58,7 @@ if score &gt;= 90:
5858
</code>
5959
</program>
6060

61-
<program language="java">
61+
<program xml:id="java-if-else" language="java">
6262
<code>
6363
public class IfElseExample {
6464
public static void main(String[] args) {
@@ -84,7 +84,7 @@ if score &gt;= 90:
8484
</p>
8585

8686

87-
<program interactive="activecode" language="python">
87+
<program xml:id="python-if-nesting" interactive="activecode" language="python">
8888
<code>
8989
grade = int(input('enter a grade'))
9090
if grade &lt; 60:
@@ -101,11 +101,11 @@ else:
101101
</program>
102102

103103
<p>
104-
In Java we have a couple of ways to write this.
104+
In Java, we have a couple of ways to write this.
105105
</p>
106106

107107

108-
<program interactive="activecode" language="java">
108+
<program xml:id="java-ifnesting" interactive="activecode" language="java">
109109
<code>
110110
public class ElseIf {
111111
public static void main(String args[]) {
@@ -133,12 +133,12 @@ public class ElseIf {
133133
</program>
134134

135135
<p>
136-
We can get even closer to the <c>elif</c> statement by taking advantage of the Java rule that a single statement does not need to be enclosed in curly braces. Since the if is the only statement used in each else we can get away with the following.
136+
We can get even closer to the <c>elif</c> statement by taking advantage of the Java rule that a single statement does not need to be enclosed in curly braces. Since the <c>if</c> is the only statement used in each <c>else</c> block, we can get away with the following.
137137
</p>
138138

139139

140140

141-
<program interactive="activecode" language="java">
141+
<program xml:id="java-if-else-no-nesting" interactive="activecode" language="java">
142142
<code>
143143
public class ElseIf {
144144
public static void main(String args[]) {
@@ -167,9 +167,9 @@ Java also supports a <c>switch</c> statement that acts something like the <c>eli
167167

168168
<note>
169169
<p>
170-
Depending on your knowledge and experience with Python you may already be familiar and questioning why we are not using the <c>match</c> statement in our Python examples. The answer is that this book currently runs its active code examples using Python 3.7, which does not support the <c>match</c> statement which was introduced in Python 3.10. Below is an example of the <c>match</c> statement similar to our grade method.
170+
Depending on your knowledge and experience with Python you may be questioning why we are not using the <c>match</c> statement in our Python examples. The answer is that this book currently runs its active code examples using Python 3.7, which does not support the <c>match</c> statement which was introduced in Python 3.10. Below is an example of the <c>match</c> statement similar to our grade method.
171171
</p>
172-
<program language="python">
172+
<program xml:id="python-match" language="python">
173173
<title>Match Case Example</title>
174174
<code>
175175
grade = 85
@@ -201,7 +201,7 @@ Java also supports a <c>switch</c> statement that acts something like the <c>eli
201201
Java 14 introduced <c>switch</c> <term>expressions</term>, enhancing functionality by allowing the <c>switch</c> to return values and eliminating <c>fall-through</c> via the <c>-&gt;</c> arrow syntax. These expressions can even use <c>yield</c> within code blocks for more complex evaluations. <term><c>yield</c></term> is used inside a switch expression’s block to produce the value of that expression, unlike <c>break</c> which simply exits a switch statement or loop. It’s important to note that traditional <c>switch</c> statements do not support <c>null</c> values and will throw a <c>NullPointerException</c> if evaluated with <c>null</c>. As the language evolves, newer versions of Java continue to extend <c>switch</c> capabilities with features like <c>pattern matching</c> and enhanced <c>type handling</c>, making it a more powerful and expressive tool for decision-making in Java programs.
202202
</p>
203203

204-
<program interactive="activecode" language="java">
204+
<program xml:id="java-switch-up" interactive="activecode" language="java">
205205
<code>
206206
public class SwitchUp {
207207
public static void main(String args[]) {
@@ -241,7 +241,7 @@ The <c>switch</c> statement is not used very often, and we recommend you do not
241241
In Python, if you want a program to continue running when an error has occurred, you can use <c>try-except</c> blocks to handle exceptions. If you wanted to write a program that asks the user to enter a whole number and then squares that number, you could use the following code to do so:
242242
</p>
243243

244-
<program interactive="activecode" language="python" xml:id="square-input-python">
244+
<program xml:id="python-square-input" interactive="activecode" language="python">
245245
<code>
246246
number = int(input("Please enter a whole number: "))
247247
squared = number ** 2
@@ -253,7 +253,7 @@ The <c>switch</c> statement is not used very often, and we recommend you do not
253253
The Java code that would perform the same task is a little more complex and utilizes the <c>Scanner</c> class for input.
254254
</p>
255255

256-
<program interactive="activecode" language="java" xml:id="square-input-java">
256+
<program xml:id="java-square-input" interactive="activecode" language="java">
257257
<code>
258258
import java.util.Scanner;
259259

@@ -275,7 +275,7 @@ The <c>switch</c> statement is not used very often, and we recommend you do not
275275
This code works well, but will end with an exception if the user types anything other than a whole number (such as 12.5 or two). If we wanted to ensure the code will continue to run until the user enters the correct format, we could add <c>try-except</c> (Python) or <c>try-catch</c> (Java) blocks within a <c>while</c> loop that iterates until the user enter the correct code. Adding <c>try-except</c> blocks and a <c>while</c> loop to the Python code will look something like this:
276276
</p>
277277

278-
<program interactive="activecode" language="python" xml:id="square-input-exception-python">
278+
<program xml:id="python-square-input-exception" interactive="activecode" language="python">
279279
<code>
280280
while True:
281281
try:
@@ -292,7 +292,7 @@ The <c>switch</c> statement is not used very often, and we recommend you do not
292292
Now that we have Python code that will continuously prompt the user until they enter a whole number, let's look at Java code that accomplishes the same task. Like most other equivalent Java code blocks, this code has a lot of extra bits that are necessary to get working code.
293293
</p>
294294

295-
<program interactive="activecode" language="java" xml:id="square-input-exception-java">
295+
<program xml:id="java-square-input-exception" interactive="activecode" language="java">
296296
<code>
297297
import java.util.Scanner;
298298
import java.util.InputMismatchException;
@@ -439,7 +439,7 @@ of an assignment statement. The following table summarizes how this works:
439439
<p>
440440
Using this operator can make code shorter and more readable in cases where a simple conditional assignment is needed.
441441
</p>
442-
<program interactive ="activecode" language ="java">
442+
<program xml:id="java-ternary" interactive ="activecode" language ="java">
443443
<code>
444444
class Main {
445445
public static void main(String[] args) {

source/ch5_loopsanditeration.ptx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
For example:
1616
</p>
1717

18-
<program interactive="activecode" language="python">
18+
<program xml:id="python-definite-loop" interactive="activecode" language="python">
1919
<code>
2020
for i in range(10):
2121
print(i)
@@ -26,7 +26,7 @@ for i in range(10):
2626
In Java, we would write this as:
2727
</p>
2828

29-
<program interactive="activecode" language="java">
29+
<program xml:id="pjava-definite-loop" interactive="activecode" language="java">
3030
<code>
3131
public class DefiniteLoopExample {
3232
public static void main(String[] args) {
@@ -65,7 +65,7 @@ public class DefiniteLoopExample {
6565
If you want to start at 100, stop at 0 and count backward by 5, the Python loop would be written as:
6666
</p>
6767

68-
<program interactive="activecode" language="python">
68+
<program xml:id="python-deinite-decrement" interactive="activecode" language="python">
6969
<code>
7070
for i in range(100, -1, -5):
7171
print(i)
@@ -76,7 +76,7 @@ for i in range(100, -1, -5):
7676
In Java, we would write this as:
7777
</p>
7878

79-
<program interactive="activecode" language="java">
79+
<program xml:id="java-definite-decrement" interactive="activecode" language="java">
8080
<code>
8181
public class DefiniteLoopBackward {
8282
public static void main(String[] args) {
@@ -97,7 +97,7 @@ public class DefiniteLoopBackward {
9797
In Python, we can iterate over a list as follows:
9898
</p>
9999

100-
<program interactive="activecode" language="python">
100+
<program xml:id="python-list-iteration" interactive="activecode" language="python">
101101
<code>
102102
l = [1, 1, 2, 3, 5, 8, 13, 21]
103103
for fib in l:
@@ -109,7 +109,7 @@ for fib in l:
109109
In Java we can iterate over an <c>ArrayList</c> of integers too. Note that this requires importing the <c>ArrayList</c> class.
110110
</p>
111111

112-
<program interactive="activecode" language="java">
112+
<program xml:id="java-list-iteration" interactive="activecode" language="java">
113113
<code>
114114
import java.util.ArrayList;
115115

@@ -134,10 +134,10 @@ public class ForEachArrayListExample {
134134

135135
<p>
136136
This example stretches the imagination a bit, and in fact points out one area where Java's primitive arrays are easier to use than an array list.
137-
In fact all primitive arrays can be used in a for each loop.
137+
In fact, all primitive arrays can be used in a <term>for each</term> loop.
138138
</p>
139139

140-
<program interactive="activecode" language="java">
140+
<program xml:id="java-for-each" interactive="activecode" language="java">
141141
<code>
142142
public class ForEachArrayExample {
143143
public static void main(String[] args) {
@@ -154,7 +154,7 @@ public class ForEachArrayExample {
154154
To iterate over the characters in a string in Java do the following:
155155
</p>
156156

157-
<program interactive="activecode" language="java">
157+
<program xml:id="java-string-iteration" interactive="activecode" language="java">
158158
<code>
159159
public class StringIterationExample {
160160
public static void main(String[] args) {
@@ -176,7 +176,7 @@ public class StringIterationExample {
176176
Both Python and Java support the <c>while</c> loop, which continues to execute as long as a condition is true.
177177
Here is a simple example in Python that counts down from 5:
178178
</p>
179-
<program interactive="activecode" language="python">
179+
<program xml:id="python-countdown" interactive="activecode" language="python">
180180
<code>
181181
i = 5
182182
while i &gt; 0:
@@ -186,9 +186,9 @@ while i &gt; 0:
186186
</program>
187187

188188
<p>
189-
In Java we add parenthesis and curly braces. Here is the same countdown loop in Java:
189+
In Java, we add parentheses and curly braces. Here is the same countdown loop in Java:
190190
</p>
191-
<program interactive="activecode" language="java">
191+
<program xml:id="java-countdown" interactive="activecode" language="java">
192192
<code>
193193
public class WhileLoopExample {
194194
public static void main(String[] args) {
@@ -210,7 +210,7 @@ public class WhileLoopExample {
210210
For example, the following loop will execute once even though the condition is initially false.
211211
</p>
212212

213-
<program interactive="activecode" language="java">
213+
<program xml:id="java-do-while" interactive="activecode" language="java">
214214
<code>
215215
public class DoWhileExample {
216216
public static void main(String[] args) {

0 commit comments

Comments
 (0)