reset password
Author Message
dvictor4
Posts: 34
Posted 17:19 Apr 08, 2017 |

Hello I have some questions on what I should return for the toString() method for MyFraction:

  1. whole numbers:
    • should I return 2 or 2/1 ?
  2. reducible fractions:
    • should I return 2/4 or 1/2?
  3. numerator is 0:
    • should I return 0/n (where n is an integer) or just 0 ?
  4. denominator is 0:
    • should I return n/0 (where n is an integer) or just NaN (not a number)?
jhurley
Posts: 207
Posted 17:54 Apr 08, 2017 |

2/1
1/2
0/n
n/0 is OK, but if you want to write the toString to show NaN, that is actually better.

 

dvictor4
Posts: 34
Posted 18:02 Apr 08, 2017 |

Got it thanks