@@ -559,7 +559,7 @@ Fraction@6ff3c5b5
559559 <program xml : id =" java-tostring" language =" java" >
560560 <code >
561561public String toString() {
562- return numerator.toString() + "/" + denominator.toString();
562+ return numerator.toString() + "/" + denominator.toString(); // convert to a string
563563}
564564 </code >
565565 </program >
@@ -598,10 +598,10 @@ object1.equals(object2)
598598
599599 <program xml : id =" java-fraction-equals" language =" java" >
600600 <code >
601- public boolean equals(Fraction other) {
602- Integer num1 = this.numerator * other.getDenominator();
603- Integer num2 = this.denominator * other.getNumerator();
604- if (num1 == num2)
601+
602+ public boolean equals(Fraction other) { // a method to compare two fractions
603+ Integer num1 = this.numerator * other.getDenominator(); Integer num2 = this.denominator * other.getNumerator();
604+ if (num1 == num2) // if the numerators are equal in value, the fractions are equal
605605 return true;
606606 else
607607 return false;
@@ -688,16 +688,16 @@ public class Fraction extends Number {
688688
689689 <program xml : id =" java-object-type-conversions" language =" java" >
690690 <code >
691- public double doubleValue() {
691+ public double doubleValue() { // convert to a double
692692 return numerator.doubleValue() / denominator.doubleValue();
693693}
694- public float floatValue() {
694+ public float floatValue() { // convert to a float
695695 return numerator.floatValue() / denominator.floatValue();
696696}
697- public int intValue() {
697+ public int intValue() { // convert to an int
698698 return numerator.intValue() / denominator.intValue();
699699}
700- public long longValue() {
700+ public long longValue() { // convert to a long
701701 return numerator.longValue() / denominator.longValue();
702702}
703703 </code >
@@ -724,7 +724,7 @@ public long longValue() {
724724 <program xml : id =" java-ugly-add-method" language =" java" >
725725 <code >
726726public void test(Number a, Number b) {
727- a.add(b);
727+ a.add(b); // this is a bad idea
728728}
729729 </code >
730730 </program >
0 commit comments