6666 </p >
6767
6868
69- <program interactive =" activecode" language =" python" >
69+ <program xml : id = " python-fracion-class1 " interactive =" activecode" language =" python" >
7070 <code >
7171 class Fraction:
7272 def __init__(self, num, den):
137137 </p >
138138
139139
140- <program language =" java" >
140+ <program xml : id = " java-fraction-class1 " language =" java" >
141141 <code >
142142 public class Fraction {
143143 private Integer numerator;
152152 </p >
153153
154154
155- <program language =" java" >
155+ <program xml : id = " java-private " language =" java" >
156156 <code >
157157 Fraction f = new Fraction(1,2);
158158 Integer y = f.numerator * 10;
168168 </p >
169169
170170
171- <program language =" java" >
171+ <program xml : id = " java-getter-and-setter " language =" java" >
172172 <code >
173173public Integer getNumerator() {
174174 return numerator;
@@ -199,7 +199,7 @@ public void setDenominator(Integer denominator) {
199199 </p >
200200
201201
202- <program language =" java" >
202+ <program xml : id = " java-fraction-constructor " language =" java" >
203203 <code >
204204public Fraction(Integer top, Integer bottom) {
205205 num = top;
@@ -220,7 +220,7 @@ public Fraction(Integer top, Integer bottom) {
220220 </p >
221221
222222
223- <program language =" java" >
223+ <program xml : id = " java-fraction-class-this " language =" java" >
224224 <code >
225225public Fraction(Integer num, Integer den) {
226226 this.num = num;
@@ -276,7 +276,7 @@ public Fraction(Integer num, Integer den) {
276276 </p >
277277
278278
279- <program language =" java" >
279+ <program xml : id = " java-fraction-class-addition " language =" java" >
280280 <code >
281281public Fraction add(Fraction otherFrac) {
282282 Integer newNum = otherFrac.getDenominator() * this.numerator +
@@ -296,11 +296,11 @@ public Fraction add(Fraction otherFrac) {
296296 <p >
297297 Second, you will notice that the method makes use of the <c >this</c > variable.
298298 In this method, <c >this</c > is not necessary, because there is no ambiguity about the <c >numerator</c > and <c >denominator</c > variables.
299- So this version of the code is equivalent:
299+ So the following version of the code is equivalent:
300300 </p >
301301
302302
303- <program language =" java" >
303+ <program xml : id = " java-fraction-class-addition2 " language =" java" >
304304 <code >
305305public Fraction add(Fraction otherFrac) {
306306 Integer newNum = otherFrac.getDenominator() * numerator +
@@ -361,7 +361,7 @@ public Fraction add(Fraction otherFrac) {
361361 </p >
362362
363363
364- <program language =" java" >
364+ <program xml : id = " java-method-overloading " language =" java" >
365365 <code >
366366public Fraction(Integer num) {
367367 this.numerator = num;
@@ -385,7 +385,7 @@ public Fraction add(Integer other) {
385385 </p >
386386
387387
388- <program interactive =" activecode" language =" java" >
388+ <program xml : id = " java-full-fraction-class " interactive =" activecode" language =" java" >
389389 <code >
390390public class Fraction {
391391 private Integer numerator;
@@ -441,7 +441,7 @@ public class Fraction {
441441 </p >
442442
443443
444- <program language =" java" >
444+ <program xml : id = " java-no-friendly-output " language =" java" >
445445 <code >
446446Fraction@6ff3c5b5
447447 </code >
@@ -531,7 +531,7 @@ Fraction@6ff3c5b5
531531 </p >
532532
533533
534- <program language =" java" >
534+ <program xml : id = " java-tostring " language =" java" >
535535 <code >
536536public String toString() {
537537 return numerator.toString() + "/" + denominator.toString();
@@ -549,18 +549,18 @@ public String toString() {
549549 </p >
550550
551551
552- <program language =" java" >
552+ <program xml : id = " java-class-equalqqual " language =" java" >
553553 <code >
554554object1 == object2
555555 </code >
556556 </program >
557557
558558 <p >
559- is NOT the same as
559+ is NOT the same as:
560560 </p >
561561
562562
563- <program language =" java" >
563+ <program xml : id = " java-class-dot-equals " language =" java" >
564564 <code >
565565object1.equals(object2)
566566 </code >
@@ -571,7 +571,7 @@ object1.equals(object2)
571571 </p >
572572
573573
574- <program language =" java" >
574+ <program xml : id = " java-fraction-equals " language =" java" >
575575 <code >
576576public boolean equals(Fraction other) {
577577 Integer num1 = this.numerator * other.getDenominator();
@@ -610,7 +610,7 @@ public boolean equals(Fraction other) {
610610 </p >
611611
612612
613- <program language =" java" >
613+ <program xml : id = " pjava-extends " language =" java" >
614614 <code >
615615public class Fraction extends Number {
616616 ...
@@ -661,7 +661,7 @@ public class Fraction extends Number {
661661 </p >
662662
663663
664- <program language =" java" >
664+ <program xml : id = " java-object-type-conversions " language =" java" >
665665 <code >
666666public double doubleValue() {
667667 return numerator.doubleValue() / denominator.doubleValue();
@@ -696,7 +696,7 @@ public long longValue() {
696696 </p >
697697
698698
699- <program language =" java" >
699+ <program xml : id = " java-ugly-add-method " language =" java" >
700700 <code >
701701public void test(Number a, Number b) {
702702 a.add(b);
@@ -745,7 +745,7 @@ public void test(Number a, Number b) {
745745 </p >
746746
747747
748- <program language =" text" >
748+ <program xml : id = " java-comparable " language =" text" >
749749 <code >
750750int compareTo(T o)
751751Compares this object with the specified object for order. Returns a
@@ -763,7 +763,7 @@ iff y.compareTo(x) throws an exception.)
763763 </p >
764764
765765
766- <program language =" java" >
766+ <program xml : id = " java-make-comparable " language =" java" >
767767 <code >
768768public class Fraction extends Number implements Comparable< Fraction> {
769769 ...
@@ -777,7 +777,7 @@ public class Fraction extends Number implements Comparable<Fraction> {
777777 </p >
778778
779779
780- <program language =" java" >
780+ <program xml : id = " java-comparable2 " language =" java" >
781781 <code >
782782public int compareTo(Fraction other) {
783783 Integer num1 = this.numerator * other.getDenominator();
@@ -794,12 +794,12 @@ public int compareTo(Fraction other) {
794794 <p >
795795 Suppose that you wanted to write a Student class so that the class could keep track of the number of students it had created.
796796 Although you could do this with a global counter variable that is an ugly solution.
797- The right way to do it is to use a static variable.
798- In Python we could do this as follows:
797+ The right way to do it is to use a < c > static</ c > variable.
798+ In Python, we could do this as follows:
799799 </p >
800800
801801
802- <program interactive =" activecode" language =" python" >
802+ <program xml : id = " python-static " interactive =" activecode" language =" python" >
803803 <code >
804804class Student:
805805 numStudents = 0
@@ -816,11 +816,11 @@ main()
816816 </program >
817817
818818 <p >
819- In Java we would write this same example using a static declaration.
819+ In Java, we would write this same example using a < c > static</ c > declaration.
820820 </p >
821821
822822
823- <program interactive =" activecode" language =" java" >
823+ <program xml : id = " java-static " interactive =" activecode" language =" java" >
824824 <code >
825825public class Student {
826826 public static Integer numStudents = 0;
@@ -855,7 +855,7 @@ public class Student {
855855 </p >
856856
857857
858- <program language =" java" >
858+ <program xml : id = " java-gcd " language =" java" >
859859 <code >
860860private static Integer gcd(Integer m, Integer n) {
861861 while (m % n != 0) {
@@ -878,7 +878,7 @@ private static Integer gcd(Integer m, Integer n) {
878878 </p >
879879
880880
881- <program interactive =" activecode" language =" java" >
881+ <program xml : id = " java-final-fraction-class " interactive =" activecode" language =" java" >
882882 <code >
883883import java.util.ArrayList;
884884import java.util.Collections;
0 commit comments