Fraction.java and Fractiontester.java

CSI 10: Assignment 6 Part I (60 points). Create a class Fraction.java This class provides representation of, and methods to manipulate fractions. A fraction consists of two integers, one for numerator and one for denominator. A valid fraction must not have zero in the denominator. We Will assume that we will be working With positive integers. A private Int to represent numerat0L Another private int to represent denominator. Create a defau t constructor which sets both numerator and denominator to I A parameterized constructor which takes the value of numerator and denominator _ Make sure the denominator is not O. If it is, set it to I _ Getters arad setters for numerator and denominator _ A method named void printFraction( which prints the fraction in the format: numerator denominator A method int computeGCD ( ) wh ch retums the largest number which divides both numerator and denominator A method void simplify( ) which reduces a fraction to its lower terms. For instance, the simplified form of fraction 6/8 is 3 4. To simplify. first find the gcd of numerator and denominator and then divide it from both the numerator and denominator. A method Fraction add (Fraction toAdd) which takes in another fraction toAdd and retums the sum of and the current fraction. A method Fraction subtract (Fraction toSub) which takes in another fraction toSub and retums the subtraction of ├╝JSub and the current fraction A method Fraction multiply (Fraction toMuIt) which takes In another fraction toMuIt and retums the multiplication of tJMuIt and the current fraction. Part 2 (40 points). Create a class FractionTester.java. Create a fraction named fracl with the second constructor _ Ask the user to enter the numerator and the denominator. Create a fraction named frac2 with the default constructor. Print both the fractions using printFractlon Simplify the fractions and then print them agaim To fracl add frac2_ Save the output in another Fraction variable. Print it using the printlnfo method. Perform the above step for subtract and multiply. What to submit ? I _ Fraction 2_ FractionTester
Powered by