Skip to content

Commit 0594728

Browse files
authored
Merge pull request #216 from habibasorour/issue_214_list
Issue 214 fixed: Listing for block of codes in 3.1
2 parents e1307ae + aa7b287 commit 0594728

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

source/ch3_javadatatypes.ptx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@
9191
</p>
9292

9393
<p>
94-
Let&#x2019;s look at a simple Python function which converts a Fahrenheit temperature to Celsius.
94+
<xref ref="python-temperature-conversion" text="type-global"/> is a simple Python function which converts a Fahrenheit temperature to Celsius.
9595
If this program were run on the command-line, you would enter the temperature when prompted &#x2013; the Javascript pop-up for input is only an artifact of the digital textbook.
9696
</p>
9797

98-
99-
<program xml:id="python-temperature-conversion" interactive="activecode" language="python">
98+
<listing xml:id="python-temperature-conversion">
99+
<program interactive="activecode" language="python">
100100
<code>
101101
def main():
102102
fahr = int(input("Enter the temperature in F: "))
@@ -105,13 +105,15 @@ def main():
105105
main()
106106
</code> <tests> </tests>
107107
</program>
108+
</listing>
108109

109110
<p>
110-
Next, lets look at the Java equivalent. If this program were run on the command-line, you would enter the temperature when prompted &#x2013; the &#x201C;Input for Program&#x201D; text box is only an artifact of the digital textbook.
111+
Next, <xref ref="java-temperature-conversion" text="type-global"/> is the Java equivalent. If this program were run on the command-line, you would enter the temperature when prompted &#x2013; the &#x201C;Input for Program&#x201D; text box is only an artifact of the digital textbook.
111112
</p>
112113

113114

114-
<program xml:id="java-temperature-conversion" interactive="activecode" language="java">
115+
<listing xml:id="java-temperature-conversion">
116+
<program interactive="activecode" language="java">
115117
<code>
116118
import java.util.Scanner;
117119
public class TempConv {
@@ -128,6 +130,7 @@ public class TempConv {
128130
}
129131
</code> <stdin> </stdin> <tests> </tests>
130132
</program>
133+
</listing>
131134

132135
<p>
133136
There are several new concepts introduced in this example. We will look at them in the following order:
@@ -247,7 +250,9 @@ public class TempConv {
247250
For Python programmers, the following error is likely to be even more common. Suppose we forgot the declaration for <c>cel</c> and instead left line 6 blank. What would happen when we type <c>javac TempConv.java</c> on the command line?
248251
</p>
249252

250-
<pre>
253+
<listing xml:id="java-temperature-conversion-error">
254+
<program>
255+
<code>
251256
TempConv.java:13: cannot find symbol
252257
symbol : variable cel
253258
location: class TempConv
@@ -259,10 +264,12 @@ public class TempConv {
259264
System.out.println("The temperature in C is: " + cel);
260265
^
261266
2 errors
262-
</pre>
267+
</code>
268+
</program>
269+
</listing>
263270

264271
<p>
265-
When you see the first kind of error, where the symbol is on the left side of the equals sign, it usually means that you have not declared the variable. If you have ever tried to use a Python variable that you have not initialized the second error message will be familiar to you. The difference here is that we see the message before we ever try to test our program. More common error messages are discussed in the section <xref ref="common-mistakes-id1"/>.
272+
When you see the first kind of error in <xref ref="java-temperature-conversion-error" text="type-global"/> , where the symbol is on the left side of the equals sign, it usually means that you have not declared the variable. If you have ever tried to use a Python variable that you have not initialized the second error message will be familiar to you. The difference here is that we see the message before we ever try to test our program. More common error messages are discussed in the section <xref ref="common-mistakes-id1"/>.
266273
</p>
267274

268275
<p>

0 commit comments

Comments
 (0)