There is a way to represent fractions over here. Is there a clear abstraction to represent mixed fractions, so that you can perform addition, subtraction, multiplication operations on it.
A mixed fraction is only a display difference and not a mathematical one. You can just convert it to mixed when you print the answer.
You could perhaps do this by extending Fraction
: you might want to add a new constructor that takes a whole number in addition to the numerator/denominator new MixedFraction(2,3,4)
for 2 3/4, and override toString
to display in the desired format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With