Skip to content

Commit b859e71

Browse files
committed
added listing tags
1 parent 7a3c89c commit b859e71

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

source/ch6_definingclasses.ptx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ public Fraction(Integer num, Integer den) {
280280
Let’s begin by implementing addition in Java:
281281
</p>
282282

283-
284-
<program xml:id="java-fraction-class-addition" language="java">
283+
<listing xml:id="java-fraction-class-addition">
284+
<program language="java">
285285
<code>
286286
public Fraction add(Fraction otherFrac) {
287287
Integer newNum = otherFrac.getDenominator() * this.numerator +
@@ -292,6 +292,7 @@ public Fraction add(Fraction otherFrac) {
292292
}
293293
</code>
294294
</program>
295+
</listing>
295296

296297
<p>
297298
First you will notice that the <c>add</c> method is declared as <c>public Fraction</c> The <c>public</c> part means that any other method may call the <c>add</c> method.
@@ -304,8 +305,8 @@ public Fraction add(Fraction otherFrac) {
304305
So the following version of the code is equivalent:
305306
</p>
306307

307-
308-
<program xml:id="java-fraction-class-addition2" language="java">
308+
<listing xml:id="java-fraction-class-addition2">
309+
<program language="java">
309310
<code>
310311
public Fraction add(Fraction otherFrac) {
311312
Integer newNum = otherFrac.getDenominator() * numerator +
@@ -316,6 +317,7 @@ public Fraction add(Fraction otherFrac) {
316317
}
317318
</code>
318319
</program>
320+
</listing>
319321

320322
<p>
321323
The addition takes place by multiplying each numerator by the opposite denominator before adding.
@@ -365,8 +367,8 @@ public Fraction add(Fraction otherFrac) {
365367
The new methods that accomplish this task are as follows:
366368
</p>
367369

368-
369-
<program xml:id="java-method-overloading" language="java">
370+
<listing xml:id="java-method-overloading">
371+
<program language="java">
370372
<code>
371373
public Fraction(Integer num) {
372374
this.numerator = num;
@@ -377,6 +379,7 @@ public Fraction add(Integer other) {
377379
}
378380
</code>
379381
</program>
382+
</listing>
380383

381384
<p>
382385
Notice that the overloading approach can provide us with a certain elegance to our code.
@@ -389,8 +392,8 @@ public Fraction add(Integer other) {
389392
You should compile and run the program to see what happens.
390393
</p>
391394

392-
393-
<program xml:id="java-full-fraction-class" interactive="activecode" language="java">
395+
<listing xml:id="java-full-fraction-class">
396+
<program interactive="activecode" language="java">
394397
<code>
395398
public class Fraction {
396399
private Integer numerator;
@@ -434,6 +437,8 @@ public class Fraction {
434437
}
435438
</code> <tests> </tests>
436439
</program>
440+
</listing>
441+
437442
</subsection>
438443
</section>
439444

0 commit comments

Comments
 (0)