// Your job is to fill in all the missing function bodies. Be sure to add your
// name to this file, and rename it!
/**
* Fraction is an object representing the ratio of two numbers: a "numerator" on
* top and a "denominator" on bottom. Objects like this can be useful when you
* need to work with exact quantities, without the rounding errors inherent in
* double
s.
*
* @author Adam Smith
* @version 1.0
*/
public class Fraction {
private int num, den;
/**
* Create a new Fraction
, from its numerator and denominator.
* @since 1.0
*/
public Fraction(int numerator, int denominator) {
}
/**
* Add a second Fraction
to this
.
* @param other the other Fraction
to add
* @return the resulting Fraction
* @since 1.0
*/
public Fraction add(Fraction other) {
return null;
}
/**
* Subtract a second Fraction
from this
.
* @param other the other Fraction
to subtract
* @return the resulting Fraction
* @since 1.0
*/
public Fraction subtract(Fraction other) {
return null;
}
/**
* Multiply a second Fraction
by this
.
* @param other the other Fraction
to multiply
* @return the resulting Fraction
* @since 1.0
*/
public Fraction multiply(Fraction other) {
return null;
}
/**
* Divide this
by a second Fraction
.
* @param other the other Fraction
by which to divide
* @return the resulting Fraction
* @since 1.0
*/
public Fraction divide(Fraction other) {
return null;
}
/**
* Calculate the double
whose value best approximates
* this
's value.
* @return the approximate value
* @since 1.0
*/
public double toDouble() {
return Double.NaN;
}
/**
* Build a String
representing this Fraction
, as
* (numerator/denominator)
.
* @return the String (numerator/denominator)
* @since 1.0
*/
@Override
public String toString() {
return null;
}
/**
* Return true
if this
Fraction
is
* equivalent to another one; otherwise false.
* @param otherObject the other object (probably a Fraction
) to
* compare with
* @return the whether they are equivalent
* @since 1.0
*/
@Override
public boolean equals(Object otherObject) {
return false;
}
/**
* Accessor for the numerator.
* @return the numerator
* @since 1.0
*/
public int getNumerator() {
return -1;
}
/**
* Accessor for the denominator.
* @return the denominator
* @since 1.0
*/
public int getDenominator() {
return -1;
}
/**
* Mutator for the numerator.
* @param newNumerator the new numerator
* @since 1.0
*/
public void setNumerator(int newNumerator) {
}
/**
* Mutator for the denominator.
* @param newDenominator the new denominator
* @since 1.0
*/
public void setDenominator(int newDenominator) {
}
// helper function to calculate the Greatest Common Divisor
private static int calcGCD(int int1, int int2) {
return -1;
}
// helper method to reduce this Fraction
// call this in the constructor and the setters to reduce
private void reduce() {
// will call calcGCD() somewhere in here
}
}