1. Engineering
  2. Computer Science
  3. please help me pass all of the tests below for...

Question: please help me pass all of the tests below for...

Question details

ÇHP8 PROGRAMMING PROJECT Implement the sei) method for the Fraction class so that it returns the minimal string That is, any value with no fractional portion must be returned as an appropeiately signed whole number(7) Any other value must be returned as a reduced fraction with just a numerator and denominator (e-1/2,7/2). In this exercise you will extend your work on classes and implement a class that encapsulates the state and behavior of an improper fraction. The name of the class must be Fraction (in a file named Fraction.java The dass has the following requirementst Implement the gedunbe) method for the rraetion class. This methodis identical to the ges5400 method for whole numbers, and for fractional numbers between-1 and 1. Fractional numbers smaller than-1 or greater than 1 must be displayed as a mixed number. A miced number consists of an optional minus sign, followed by a whole number, followed by an anderscore, followed by the namerator, followed by a /,tollowed by a denominator. For example, REQUIREMENTS the improper fraction-5/4 corresponds to the mixed number-1 1/4 Two d fields representing a numerator and a denominator- The fields must be properly encapsulated to prevent direct access from outside the class. That means the fields must be private and you must implement accessor methods as appropriate . Implement the conese method. The method must take a singe Fraction parameter and retum an ins. The sos must follow standard seee pattensimut be negative if the curreat Frastion is less than the parameter, You may not have any other felds positive if the current Fraction is greatee than the parameter, and zero if the two Fracsions are equal. Your class must not display anything (with a prine, อ64aslo, etc), and your class must not have a main method. then use the provided Testva fle (which has a main method) to test and verity the correctness of yoar implementation. You can The class must enforce the invariant that the numerator and denominator are fully redaced, and that the denominator is not negative Three constructors that accept the sets of parameters described below and appropriately set the two fields deseribed above SAMPLE USAGE In this sample we decare and instantiate a Facion . We set the value to 6/4, then call sds to display the values returned by Duseases and go9es9soenaseThis must display the values 3 and 2 respectively, Finaly we 。The first constructor must accept two ม沌Parameters representing a numerator and denominator(in that order) Any two įAR are valid, except the constructor must ensure that the denominate must throw an เร aot 0, Otherwise the constructor imilar to the following code multiply Eby itself and print out the result-yieldiag the nal value of 9/4 throw new 33deeeuresece denessage goes here The second constructor must accept a single integer parameter representing a ซ0eieswese Any us is a valid whole aumber. o SCORING 1砒Ctotal of 2) each for proper field declaration and in:talization 2 pts (total of 6) for each working constructor 3 pts for proper reduction during construction 2 pts Ctotal of 8) each for each working operator 3pts for proper output froms the tt method 3pts for proper output from the 2 pts for proper output from the c0 mechod 3pts for proper coding style, indentation, whitespace,comments Total of 30 o The third, and last constructor must accept a single ธ ring parameter representing an improper fraction. An improper fraction has an optional leading sgn character (+ or-), followed by a number. followed by a slash character, follawed by a ponzero number, mproper fraction are จ There NUST be no space between any of the characters, The general forms for an method Valid examples for an improper fraction are 1/2 -2/4 EXTRA CREDIT In addition to the Praction class, create a BisEraction class. The BisFrastian class should be mostly ideatical to the Fraction class, escept it can handle numerators and denominators with many more digits than the Fraction class. The BisFraciaa class wall do this by using the iva matb Biglategecclass for its numerator and denominator,Bigrasipp should keep the three constructors of Fraction, and in addition have two new constructors that take Salangen instead of u% All methods that take For the purposes of this assignment, the input string is guarasteed to be valid. e In order to maintainthe invariant, all constructors must reduce the fraction, That is, if the user calls new Praciane ),then the stored values for the numerator and denominator are 3 and 4 respectively. n as a parameter should take a BisFraction instead You are expected to look up information about the Bisiateeet class, and figure out how to use it yourself. Discovering and using code you didnt write by doing research and reading documentation is a big part of real life software development. . You must impletour instance ot static) methods that implement familiar mathematical operations. The methods must be named add, aubsraes, malsiply and divide. Each method must take a single Fraceion parameter and return a Fxaation Nsult The methods must not modity the curent object, or the parameter, in the case where the parameter represents the fraction 0, the dsvide method must throw an dlesasesesea RAVCA Riv:A

please help me pass all of the tests below for this problem.


  

test("123/456 + 123/456", "41/76", "41/76", 41, 76);
test("-123/456 + -123/456", "-41/76", "-41/76", -41, 76);
test("+123/456 + +123/456", "41/76", "41/76", 41, 76);

// valid that cannot be reduced (uses primes)
test("1/2210 + 1/4389", "6599/9699690", "6599/9699690", 6599, 9699690);
test("1/2210 - 1/4389", "2179/9699690", "2179/9699690", 2179, 9699690);
test("1/2210 * 1/4389", "1/9699690", "1/9699690", 1, 9699690);
test("1/2210 / 1/4389", "4389/2210", "1_2179/2210", 4389, 2210);
test("23/2210 + 41/4389", "191557/9699690", "191557/9699690", 191557, 9699690);
test("29/2210 - 43/4389", "32251/9699690", "32251/9699690", 32251, 9699690);
  
test("31/2210 * 47/4389", "1457/9699690", "1457/9699690", 1457, 9699690);
test("37/2210 / 53/4389", "162393/117130", "1_45263/117130", 162393, 117130);
test("30/77 + 77/30", "6829/2310", "2_2209/2310", 6829, 2310);
test("30/77 - 77/30", "-5029/2310", "-2_409/2310", -5029, 2310);
test("30/77 * 77/30", "1", "1", 1, 1);
test("30/77 / 77/30", "900/5929", "900/5929", 900, 5929);
test("30/77 + -77/30", "-5029/2310", "-2_409/2310", -5029, 2310);
test("30/77 - -77/30", "6829/2310", "2_2209/2310", 6829, 2310);
test("30/77 * -77/30", "-1", "-1", -1, 1);
test("30/77 / -77/30", "-900/5929", "-900/5929", -900, 5929);
  
// whole and whole
test("123/1 + 456/1", "579", "579", 579, 1);
test("123/1 - 456/1", "-333", "-333", -333, 1);
test("123/1 * 456/1", "56088", "56088", 56088, 1);
test("123/1 / 456/1", "41/152", "41/152", 41, 152);
test("123/1 + +456/1", "579", "579", 579, 1);
test("123/1 - +456/1", "-333", "-333", -333, 1);
test("123/1 * +456/1", "56088", "56088", 56088, 1);
test("123/1 / +456/1", "41/152", "41/152", 41, 152);
test("+123/1 + 456/1", "579", "579", 579, 1);
test("+123/1 - 456/1", "-333", "-333", -333, 1);
test("+123/1 * 456/1", "56088", "56088", 56088, 1);
test("+123/1 / 456/1", "41/152", "41/152", 41, 152);
test("123/1 + -456/1", "-333", "-333", -333, 1);
test("123/1 - -456/1", "579", "579", 579, 1);
test("123/1 * -456/1", "-56088", "-56088", -56088, 1);
test("123/1 / -456/1", "-41/152", "-41/152", -41, 152);
test("-123/1 + 456/1", "333", "333", 333, 1);
test("-123/1 - 456/1", "-579", "-579", -579, 1);
test("-123/1 * 456/1", "-56088", "-56088", -56088, 1);
test("-123/1 / 456/1", "-41/152", "-41/152", -41, 152);
  
// whole and fraction
test("1/1 + 1/2", "3/2", "1_1/2", 3, 2);
test("2/1 - 1/2", "3/2", "1_1/2", 3, 2);
test("3/1 * 1/2", "3/2", "1_1/2", 3, 2);
test("4/1 / 1/2", "8", "8", 8, 1);
test("1/1 + +1/2", "3/2", "1_1/2", 3, 2);
test("2/1 - +1/2", "3/2", "1_1/2", 3, 2);
test("3/1 * +1/2", "3/2", "1_1/2", 3, 2);
test("4/1 / +1/2", "8", "8", 8, 1);
test("+1/1 + 1/2", "3/2", "1_1/2", 3, 2);
test("+2/1 - 1/2", "3/2", "1_1/2", 3, 2);
test("+3/1 * 1/2", "3/2", "1_1/2", 3, 2);
test("+4/1 / 1/2", "8", "8", 8, 1);
test("1/1 + -1/2", "1/2", "1/2", 1, 2);
test("2/1 - -1/2", "5/2", "2_1/2", 5, 2);
test("3/1 * -1/2", "-3/2", "-1_1/2", -3, 2);
test("4/1 / -1/2", "-8", "-8", -8, 1);
test("-1/1 + -1/2", "-3/2", "-1_1/2", -3, 2);
test("-2/1 - -1/2", "-3/2", "-1_1/2", -3, 2);
test("-3/1 * -1/2", "3/2", "1_1/2", 3, 2);
test("-4/1 / -1/2", "8", "8", 8, 1);

// fraction and whole
test("1/2 + 1/1", "3/2", "1_1/2", 3, 2);
test("1/2 - 2/1", "-3/2", "-1_1/2", -3, 2);
test("1/2 * 3/1", "3/2", "1_1/2", 3, 2);
test("1/2 / 4/1", "1/8", "1/8", 1, 8);
test("+1/2 + 1/1", "3/2", "1_1/2", 3, 2);
test("+1/2 - 2/1", "-3/2", "-1_1/2", -3, 2);
test("+1/2 * 3/1", "3/2", "1_1/2", 3, 2);
test("+1/2 / 4/1", "1/8", "1/8", 1, 8);
test("1/2 + +1/1", "3/2", "1_1/2", 3, 2);
test("1/2 - +2/1", "-3/2", "-1_1/2", -3, 2);
test("1/2 * +3/1", "3/2", "1_1/2", 3, 2);
test("1/2 / +4/1", "1/8", "1/8", 1, 8);
test("1/2 + -1/1", "-1/2", "-1/2", -1, 2);
test("1/2 - -2/1", "5/2", "2_1/2", 5, 2);
test("1/2 * -3/1", "-3/2", "-1_1/2", -3, 2);
test("1/2 / -4/1", "-1/8", "-1/8", -1, 8);
test("-1/2 + 1/1", "1/2", "1/2", 1, 2);
test("-1/2 - 2/1", "-5/2", "-2_1/2", -5, 2);
test("-1/2 * 3/1", "-3/2", "-1_1/2", -3, 2);
test("-1/2 / 4/1", "-1/8", "-1/8", -1, 8);
test("-1/2 + -1/1", "-3/2", "-1_1/2", -3, 2);
test("-1/2 - -2/1", "3/2", "1_1/2", 3, 2);
test("-1/2 * -3/1", "3/2", "1_1/2", 3, 2);
test("-1/2 / -4/1", "1/8", "1/8", 1, 8);

// these will fail if program does not
// properly find duplicate factors
test("2048/4096 + 2048/4096", "1", "1", 1, 1);
test("2048/4096 - 2048/4096", "0", "0", 0, 1);
test("2048/4096 * 2048/4096", "1/4", "1/4", 1, 4);
test("2048/4096 / 2048/4096", "1", "1", 1, 1);
test("2048/4096 + +2048/4096", "1", "1", 1, 1);
test("2048/4096 - +2048/4096", "0", "0", 0, 1);
test("2048/4096 * +2048/4096", "1/4", "1/4", 1, 4);
test("2048/4096 / +2048/4096", "1", "1", 1, 1);
test("+2048/4096 + 2048/4096", "1", "1", 1, 1);
test("+2048/4096 - 2048/4096", "0", "0", 0, 1);
test("+2048/4096 * 2048/4096", "1/4", "1/4", 1, 4);
test("+2048/4096 / 2048/4096", "1", "1", 1, 1);
test("2048/4096 + -2048/4096", "0", "0", 0, 1);
test("2048/4096 - -2048/4096", "1", "1", 1, 1);
test("2048/4096 * -2048/4096", "-1/4", "-1/4", -1, 4);
test("2048/4096 / -2048/4096", "-1", "-1", -1, 1);
test("-2048/4096 + 2048/4096", "0", "0", 0, 1);
test("-2048/4096 - 2048/4096", "-1", "-1", -1, 1);
test("-2048/4096 * 2048/4096", "-1/4", "-1/4", -1, 4);
test("-2048/4096 / 2048/4096", "-1", "-1", -1, 1);
test("-2048/4096 + -2048/4096", "-1", "-1", -1, 1);
test("-2048/4096 - -2048/4096", "0", "0", 0, 1);
test("-2048/4096 * -2048/4096", "1/4", "1/4", 1, 4);
test("-2048/4096 / -2048/4096", "1", "1", 1, 1);

// fractions same denominator
test("1/2 + 1/2", "1", "1", 1, 1);
test("1/2 - 1/2", "0", "0", 0, 1);
test("1/2 * 1/2", "1/4", "1/4", 1, 4);
test("1/2 / 1/2", "1", "1", 1, 1);
test("1/2 + +1/2", "1", "1", 1, 1);
test("1/2 - +1/2", "0", "0", 0, 1);
test("1/2 * +1/2", "1/4", "1/4", 1, 4);
test("1/2 / +1/2", "1", "1", 1, 1);
test("+1/2 + 1/2", "1", "1", 1, 1);
test("+1/2 - 1/2", "0", "0", 0, 1);
test("+1/2 * 1/2", "1/4", "1/4", 1, 4);
test("+1/2 / 1/2", "1", "1", 1, 1);
test("1/2 + -1/2", "0", "0", 0, 1);
test("1/2 - -1/2", "1", "1", 1, 1);
test("1/2 * -1/2", "-1/4", "-1/4", -1, 4);
test("1/2 / -1/2", "-1", "-1", -1, 1);
test("-1/2 + 1/2", "0", "0", 0, 1);
test("-1/2 - 1/2", "-1", "-1", -1, 1);
test("-1/2 * 1/2", "-1/4", "-1/4", -1, 4);
test("-1/2 / 1/2", "-1", "-1", -1, 1);
test("-1/2 + -1/2", "-1", "-1", -1, 1);
test("-1/2 - -1/2", "0", "0", 0, 1);
test("-1/2 * -1/2", "1/4", "1/4", 1, 4);
test("-1/2 / -1/2", "1", "1", 1, 1);

// fractions different denominator
test("1/2 + 1/3", "5/6", "5/6", 5, 6);
test("1/2 - 1/3", "1/6", "1/6", 1, 6);
test("1/2 * 1/3", "1/6", "1/6", 1, 6);
test("1/2 / 1/3", "3/2", "1_1/2", 3, 2);
test("1/2 + +1/3", "5/6", "5/6", 5, 6);
test("1/2 - +1/3", "1/6", "1/6", 1, 6);
test("1/2 * +1/3", "1/6", "1/6", 1, 6);
test("1/2 / +1/3", "3/2", "1_1/2", 3, 2);
test("+1/2 + 1/3", "5/6", "5/6", 5, 6);
test("+1/2 - 1/3", "1/6", "1/6", 1, 6);
test("+1/2 * 1/3", "1/6", "1/6", 1, 6);
test("+1/2 / 1/3", "3/2", "1_1/2", 3, 2);
test("1/2 + -1/3", "1/6", "1/6", 1, 6);
test("1/2 - -1/3", "5/6", "5/6", 5, 6);
test("1/2 * -1/3", "-1/6", "-1/6", -1, 6);
test("1/2 / -1/3", "-3/2", "-1_1/2", -3, 2);
test("-1/2 + 1/3", "-1/6", "-1/6", -1, 6);
test("-1/2 - 1/3", "-5/6", "-5/6", -5, 6);
test("-1/2 * 1/3", "-1/6", "-1/6", -1, 6);
test("-1/2 / 1/3", "-3/2", "-1_1/2", -3, 2);
test("-1/2 + -1/3", "-5/6", "-5/6", -5, 6);
test("-1/2 - -1/3", "-1/6", "-1/6", -1, 6);
test("-1/2 * -1/3", "1/6", "1/6", 1, 6);
test("-1/2 / -1/3", "3/2", "1_1/2", 3, 2);
  
//compareTo
test("0/1 < 1/1", "-1", "", 0, 0);
test("0/1 < 2/1", "-1", "", 0, 0);
test("1/1 < 0/1", "1", "", 0, 0);
test("2/1 < 0/1", "1", "", 0, 0);
test("123/456 < -456/123", "1", "", 0, 0);
test("-123/456 < 456/123", "-1", "", 0, 0);
test("24/48 < 2/4", "0", "", 0, 0);
test("1/2 < 49/99", "1", "", 0, 0);
test("49/99 < 1/2", "-1", "", 0, 0);
  

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution