2.8.9: Concatenating Fractions
Implement getNumerator and getDenominator. Then fill in the toString method so that it returns a Fraction in the form "numerator/denominator", such as "1/2" or "16/20".
FractionTester.java
import java.util.Scanner;
public class FractionTester
{
public static void main(String[] args)
{
// Create objects
Scanner input = new Scanner(System.in);
// Ask for input
// Create new Fraction with the user's input
// Add the fractions
// Make use of the getDenominator and getNumerator methods
// Print out the fractions as an equation
// Remember you don't have to call toString yourself!
}
}
Fraction.java
public class Fraction
{
private int numerator;
private int denominator;
public Fraction(int numer, int denom)
{
numerator = numer;
denominator = denom;
numer = 0;
denom = 1;
}
public Fraction1 (int getNumerator, int getDenominator);
{
getNumerator = numer;
getDenominator = denom;
}
// Returns the numerator
public int getNumerator()
{
return numer;
}
// Returns the denominator
public int getDenominator()
{
int denom;
return denom;
}
// Returns a string representing a fraction
// in the form
// numerator/denominator
public String toString()
{
return numerator + "/" + denominator;
}
}