Skip to content

This assignment provides you the opportunity to work with fr

    This assignment provides you the opportunity to work with fractions as a new abstract data type! You should be able to help third and fourth graders with their homework when you complete this exercise!What to hand in:Please hand in code listings and output that are legible and formatted for ease of reading.Canvas submission instructions:Please combine multiple files into a single ‘zip’ archive, and save it in a location that you will remember. When you are ready to submit the assignment, open the assignment you are submitting a solution for, and attach your file.Problems:Derive a new kind of Number called Fraction. Give it appropriate methods to add, subtract, multiply and divide fractions. Also, provide the required methods for a Number (to be sortable, it should also implement Comparable

    ).Determine some appropriate way to convert a Fraction to a String, and implement the appropriate method. Simply outputting the double equivalent is not a satisfactory answer.You must provide a method (which could be private) to simplify your Fraction into lowest terms. That method could be used after every operation changing the Fraction, and certainly is required to provide a reasonable comparison operation.Make sure to implement equals so you have a way to compare Fractions.Create a main method or test class with a main method with adequate number of test cases to demonstrate that your Fraction behaves appropriately.Notes:A fraction has a numerator and a denominator (the part above the line and the part below the line).The denominator may not be zero (0).If the denominator is one (1), the Fraction represents the integer in the numerator, and should be converted to a String just like an integer.Remember the rules for addition, subtraction, multiplication, and division of fractions:To simplify a Fraction, one divides the numerator and denominator by the greatest common divisor, which is the largest number that divides each of them evenly.If you are not using BigInteger, you can use the following gcd method. It can be modified to use long instead of int:/* As a static method using int */public static int greatestCommonDivisor (int int1, int int2){ int temp; if ( int1 < 0 ) int1 = -int1; if ( int2 < 0 ) int2 = -int2; while ( int2 != 0) { temp = int1 % int2; // % is the modulus operator int1 = int2; int2 = temp; } return int1;}Additionally, one should ensure the denominator is positive. If you are using BigInteger to represent the components, you compare to zero with compareTo and use negate to reverse the sign.Once you simplify, you can compare Fractions by manipulating denominators and numerators. Hint: For compareTo you can subtract them and look at the result.If you use BigInteger to represent these components, you will get a gcd method to go along with it!BigInteger also provides a satisfactory set of name expectations for the operations one might expect on a Fraction. These are worth consulting!To create fractions, it is sensible to have a String constructor. A sample constructor is provided below (this one uses the BigInteger data members; a somewhat simpler, but similar one would work with long data members):public Fraction (String fractionString) throws NumberFormatException { String[] parts = fractionString.split(‘/’); denominator = BigInteger.ONE; numerator = BigInteger.ZERO; // The BigInteger constructor may throw NumberFormatExceptions if ( parts.length == 0 || parts.length > 2 ) { throw new NumberFormatException(‘Illegally formatted Fraction’); } numerator = new BigInteger(parts[0].trim()); if ( parts.length == 2 ) { BigInteger d = new BigInteger(parts[1].trim()); if ( d.equals(BigInteger.ZERO)) throw new NumberFormatException(‘Fraction may not have zero denominator’); denominator = d; } simplify();}Remember: Delegate, delegate, delegate!Evaluation Criteria:CriteriaWeightCreation of the Fraction type and its components, including a String constructor.20Add, Subtract, Multiply, and Divide operations20All required Number methods20simplify and toString methods10Method for comparison of Fractions (equals, compareTo)10Main program with an adequate number of test cases to demonstrate the above20

    You can hire someone to answer this question! Yes, has paper writers, dedicated to completing research and summaries, critical thinking tasks, essays, coursework, and other homework tasks. Its fast and safe.