Question: Complete this code (Instructions are all provided inside the functions) public class Fraction { private int numerator; private int denominator; /* * DO NOT MODIFY

Complete this code (Instructions are all provided inside the functions)

public class Fraction { private int numerator; private int denominator; /* * DO NOT MODIFY THIS CONSTRUCTOR. * We have already completed this method for you. * We have set the numerator to 0 and the denominator to 1 */ public Fraction() { numerator=0; denominator=1; } // end default constructor /* * TODO: Refer to the earlier constructor to help you complete this. * 1. If the initialDenominator is 0, then you must set it to 1. This is not ideal, and * a more ideal solution would throw an exception. However, we have't looked at * exceptions, and I ask you instead to simply set the denominator of your fraction to 1 * only if the initialDenominator is 0. * * 2. At the very end you must call the methods adjustSigns() and reduceToLowestTerms(). * The method reduceToLowestTerms() has been already completed for you. However, you must * complete the method adjustSigns(). */ public Fraction(int initialNumerator, int initialDenominator) { } // end constructor /* * TODO: You must simply return back the numerator of your fraction. * This method must contain only 1 line of code inside its body */ public int getNumerator() { } // end getNumerator /* * TODO: You must simply return back the denominator of your fraction. * This method must contain only 1 line of code inside its body */ public int getDenominator() { } // end getDenominator /* * TODO: The add method must return back a new fraction which is represented * as the addition of the two fractions i.e., this AND operand. * Here is how you add two fractions: * a/b + c/d is (ad + cb)/(bd) * */ public Fraction add(Fraction operand) { } // end add /* * TODO: The subtract method must return back a new fraction which is represented * as the subtraction of the two fractions i.e., this AND operand. * Here is how you add two fractions: * a/b - c/d is (ad - cb)/(bd) * */ public Fraction subtract(Fraction operand) { } // end subtract /* * TODO: The multiply method must return back a new fraction which is represented * as the subtraction of the two fractions i.e., this AND multiplier. * Here is how you add two fractions: * a/b * c/d is (ac)/(bd) * */ public Fraction multiply(Fraction multiplier) { } // end multiply /* * TODO: The divide method must return back a new fraction which is represented * as the subtraction of the two fractions i.e., this AND divisor. * Here is how you add two fractions: * (a/b) / (c/d) is (ad)/(bc) * The divide method must make use of the getReciprocal on the divisor * and the multiply method. * */ public Fraction divide(Fraction divisor) { } // end divide public Fraction getReciprocal() { } // end getReciprocal /* TODO: If fraction this>other then return back +1 * if fraction this==other then return back 0 * if fraction this                                            

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!