From e7368957fb0dbf8be5633d126aaae50a152b50c3 Mon Sep 17 00:00:00 2001 From: Habiba Sorour Date: Fri, 31 Jul 2026 23:55:17 +0300 Subject: [PATCH] added comments to code --- source/ch6_definingclasses.ptx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/source/ch6_definingclasses.ptx b/source/ch6_definingclasses.ptx index c1b2d6f..aa0a311 100644 --- a/source/ch6_definingclasses.ptx +++ b/source/ch6_definingclasses.ptx @@ -559,7 +559,7 @@ Fraction@6ff3c5b5 public String toString() { - return numerator.toString() + "/" + denominator.toString(); + return numerator.toString() + "/" + denominator.toString(); // convert to a string } @@ -598,10 +598,10 @@ object1.equals(object2) -public boolean equals(Fraction other) { - Integer num1 = this.numerator * other.getDenominator(); - Integer num2 = this.denominator * other.getNumerator(); - if (num1 == num2) + +public boolean equals(Fraction other) { // a method to compare two fractions + Integer num1 = this.numerator * other.getDenominator(); Integer num2 = this.denominator * other.getNumerator(); + if (num1 == num2) // if the numerators are equal in value, the fractions are equal return true; else return false; @@ -688,16 +688,16 @@ public class Fraction extends Number { -public double doubleValue() { +public double doubleValue() { // convert to a double return numerator.doubleValue() / denominator.doubleValue(); } -public float floatValue() { +public float floatValue() { // convert to a float return numerator.floatValue() / denominator.floatValue(); } -public int intValue() { +public int intValue() { // convert to an int return numerator.intValue() / denominator.intValue(); } -public long longValue() { +public long longValue() { // convert to a long return numerator.longValue() / denominator.longValue(); } @@ -724,7 +724,7 @@ public long longValue() { public void test(Number a, Number b) { - a.add(b); + a.add(b); // this is a bad idea }