## Class Fraction

• public class Fraction
extends Object
Representing Fractions
• ### Constructor Summary

Constructors
Constructor Description
Fraction​(long numerator, long denominator)
• ### Method Summary

All Methods
Modifier and Type Method Description
Fraction add​(Fraction f)
Add a second fraction to the current instance.
long getDenominator()
long getNumerator()
double getValue()
Fraction mult​(Fraction f)
Multiply a second fraction by this instance
void setDenominator​(long denominator)
void setNumerator​(long numerator)
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Constructor Detail

• #### Fraction

public Fraction​(long numerator,
long denominator)
Parameters:
numerator - The fraction's numerator.
denominator - The fraction's denominator.
• ### Method Detail

• #### getValue

public double getValue()
Returns:
The fraction's decimal value e.g. 1/3 = 0.3333...
• #### getNumerator

public long getNumerator()
Returns:
The fraction's numerator
• #### setNumerator

public void setNumerator​(long numerator)
Parameters:
numerator - Set the fraction's numerator.
• #### getDenominator

public long getDenominator()
Returns:
The fraction's denominator value
• #### setDenominator

public void setDenominator​(long denominator)
Parameters:
denominator - Set the fraction's denominator

public Fraction add​(Fraction f)
Add a second fraction to the current instance.
Parameters:
f - A second fraction.
Returns:
The sum of the current instance and f according to: ${a\over b} + {x\over y} = {{ay + bx}\over by}$
• #### mult

public Fraction mult​(Fraction f)
Multiply a second fraction by this instance
Parameters:
f - Building the product with this second fraction.
Returns:
The result of multiplying the current instance by f according to: ${a\over b} \cdot {x\over y} = {{ax}\over by}$