Creating the toString method

By default, all classes in Java have a toString method. The toString method is simply a method that returns the String representation or state of an object. The default functionality of toString is usually not desirable as it returns the memory address of an object in String format (this will be made more clear later on in the semester). For now, we will create our own version of toString that more aptly represents a Fraction as a String. This is what the output should look like

	numerator = 2
	denominator = 7

To achieve this, we will form a String by concatenating Fraction's numerator and denominator values.

/**
 * Returns a String representation of this Fraction.
 * Precondition: None
 * Postcondition: None
 * @param None
 * @return A String representation of this Fraction
 */
public String toString()
{
	//Create a String variable Eg. String str = " \n"
	//Append to the variable, the value you want to display Eg. str += " "
	//return the string
}

Testing

Since we now have a constructor and a toString method, we may run the first part of our test program. Two Fractions will be constructed via user input and the toString method will be invoked to output the Fractions to the console.

Un-comment the first block of code in the main method of FractionDriver.java.

Run your code to make sure everything you have implemented so far works. It is easier to find errors if you write and then test a little bit at a time, rather than writing an entire project at once and then attempting to debug the entire thing.