Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Lab Description Create a Rational class to store fractions. Addition Logic 50 the new numerator (numi den2 num2denl the new denominator(deniden2) Files Needed Rational.1ava RationalRunner.1ava
Lab Description Create a Rational class to store fractions. Addition Logic 50 the new numerator (numi den2 num2denl the new denominator(deniden2) Files Needed Rational.1ava RationalRunner.1ava you must also reduce the fraction Sample Output: test-1/1 test. eguals (newone) false 1/2.equals (2/3)false 2/3.equals (4/6)true rone.compareTo (rTwo)1 rTwo.compareTo (rone1 1/2.add 1/3)-5/6 4/10.add (3/5)1/1 2/10.add (3/6)7/10 1/4.equals (2/8)true 1/4.add (2/8) -1/2 1/6.equals (2/8)false 1/6.add (28)-5/12 import static java.lang.System.* class Rational implements ComparablecRational> //add two instance variables //write two constructors //write a setRational method //write a set method for numerator and denominator public void add (Rational other) / umi/deni + num2/den2 /ew numeratornumi den2 num2den1) /ew denominator(denl den2) reduce (); private void reduce () private int ged(int numOne, int numTwo) return 1; public Object clone () return ""; //ACCESSORS //write get methods for numerator and denominator public boolean equals( object obj) return false; public int compareTo (Rational other) return-1; //write tostring() method import static java.lang.System. public class RationalRunner public static void main( String args) Rational testnew Rational out .print In(.test + test); Rational newone new Rational ( 3 , 4 ) ; out.println( newone+newOne) out .printIn(.test.equals(newone) # .+test.equals(new0ne)); newone-(Rational test.clone) out.printIn(. newone after test.clone() # .+newone); out . print In(.test.equals(newone) = .+test.equals(newOne )); Rational rone new Rational ( 1 , 2 ) ; Rational rTwo -new Rational (2,3) out .print In("1/2.equals(2/3) = +rone .equals(rTwo)); test.setRational (4,6) out.println 2/3.equals (4/6) rTwo.equals (test) out.printIn(. rone = .+rone); out .print In(.rTwo= +rTwo); out . print In ( . rone . compareTo ( rTwo ) # . +rone . compareTo ( rTwo ) ) ; out . print In ( . rTwo . compareTo ( rone ) # . +rTwo . compareTo ( rone ) ) ; rone.add (rTwo) out.println n nrone.add (rTwo+rone rOne.setRational(1,2) rTwo.setRational (1,3) rone.add (rTwo) out .printin("inini/2.add(1/3) = + rone); rOne.setRational (4, 10) rTwo.setRational (3,5) rone.add (rTwo) out .print 1n (. 4/10.add (3/5) -+ rone); rOne.setRational (2,10) rTwo.setRational (3,6) rone.add (rTwo) out .print 1n (. 2/10.add (3/6) -+ rone); rOne.setRational (1,4) rTwo.setRational (2,8) out .print In(. 1/4.equals(2/8) .+rone .equals(rTwo)); rone.add (rTwo) out .print In(. 1/4.add(2/8) .+ rone); rOne.setRational (1,6) rTwo.setRational (2,8) out .print In(. 1/6.equals(2/8) +rone .equals(rTwo)); rone.add (rTwo) out . print In(' 1/6.add(2/8) .+ rone)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started