Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

both codes have to be connected to each other how do I fix both codes. The Fraction class definition accurately reflects the UML diagram provided

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

both codes have to be connected to each other how do I fix both codes.

The Fraction class definition accurately reflects the UML diagram provided in the Project5 resource documents. The 20pts 0pts reduce( ) method is Full Marks called in the 5/20pts constructor so that Comments all Fraction objects many bigs are automatically reduced to their lowest terms view longer description The driver class (i.e. FractionDemo.java) 10pts 0pts correctly Full Marks No Marks instantiates two 5/10 pts Fraction objects, reduced to lowest Comments terms. manybugs view longer description on your computer and then go The program The program gives correct output (i.e. two Fractions are correctly added, subtracted, 30pts0pts multiplied and Full Marks Norks divided, and the 0/30 pts double representation is Comments no output correctly implemented) view longer description 77 // Returns the new Fraction object 78 public Fraction multiply(Fraction f2) 78publicFractionmultiply79{80// Local variables for the new numerator and new denominator 81 int newNum, newDenom; 82// Get the new numerator by multiplying the two numerators newNum =( this getNum()f2getNum()); 86 // Get the new denominator by multiplying the two denominators newDenom = this getDenom()f2getDenom(); // Call constructor to instantiate the new Fraction \} return new Fraction (newNum, newDenom); 92 93// tostring to format how to display all fractions 94 public String tostring() 95\{ // Local string variable to format the fraction String strfraction; if ( denom ==1 ) \{ // If denom is 1 , this is an integer strfraction ="("+ num +")"; \}) else \{ strfraction ="("+ num +"/"+ denom +")"; 3 return strfraction; \} 3 //end of Fraction class definition 9 16 / Simport statements for scanner clas 5 11 import java.util. scanner; 12 13 //Definition of Fraction class 14 class FractionDemo\{ 15 //Declaration of private data membens private int num; private int denom; //Definition of parameterized constructon public FractionDemo(int n, int d) \{ num =n; this.setDenom(d); this.reduceFraction (); this.adjustsign(); \} //Definition of setNum method that is used to set the Malue of num variable public void setNum (int n){ num =n; \} //Definition of setNum method that is used to set the walue of denom variable public void setDenom(int d) \{ //If condition to check if the value of denominaton is zeno if (d!=0) \{ denom =d \} l/if value is zero reseting the value to 1 and printing message to screen else \{ System.out.println("For Fraction: "+this.tostring()+ +:"; System.out.println("Denominator cannot be zero; denominaton value is being reset to one"); denom =1 System.out.println("The Fraction is now: "+ this.tostring())): \} \} //Definition of getter method for num public int getNum()\{ Fraction res = new Fraction (newNum, newDenom); // reducing the resulting fraction into simplest form res.reduceFraction( ); return res; 3 public Fraction substract(Fraction F2) \{ int newNum, newDenom; int gcd=gcd( this. denom, F2.denom ); // Denominator of resulting fraction would be the LCM of both denominators // finding LCM of both denominator using GCD //LCMGCD=ab newDenom =( this. denom F2. denom )/gcd; I/ Changing the fractions to have same denominator // Numerator of the resulting fraction can now be calculated newNum =(this.num)( newDenom/this. denom )(F2num)( newDenom/F2. denom ); Fraction res = new Fraction(newNum, newDenom) ; //reducing the resulting fraction into simplest form res.reducefraction(); return res; \} //definition of getDouble method that returns the floating point value of the fraction public double getDouble() \{ double res =( double)this.num / (double) this. denom; return res; \} \} All integer values are positive: Enter the numerator of the first fraction: 5 Enter the denominator of the first fraction: 8 Enter the numerator of the second fraction: 3 Enter the denominator of the second fraction: 10 f1==(5/8) f2==(3/10) (5/8)==0.6250 (3/10)==0.3000 (5/8)(3/10)==(3/16) (5/8)/(3/10)==(25/12) (5/8)+(3/10)=(37/40) (5/8)(3/10)==(13/40) All integer values are negative: - When both numerator and denominator are negative, the Fraction is positive Enter the numerator of the first fraction: 5 Enter the denominator of the first fraction: 8 Enter the numerator of the second fraction: 3 Enter the denominator of the second fraction: 10 f1 =(5/8) f2 =(3/10) (5/8)==0.6250 (3/10)==0.3000 (5/8)(3/10)==(3/16) (5/8)/(3/10)==(25/12) (5/8)+(3/10)==(37/40) (5/8)(3/10)=(13/40) Both Fraction objects are negative: Enter the numerator of the first fraction: 5 Enter the denominator of the first fraction: 8 Enter the numerator of the second fraction: 3 Enter the denominator of the second fraction: 10 f1==(5/8) f2==(3/10) (5/8)==0.6250 (3/10)==0.3000 (5/8)(3/10)==(3/16) (5/8)/(3/10)==(25/12) (5/8)+(3/10)==(37/40) (5/8)(3/10)==(13/40) The Fraction class definition accurately reflects the UML diagram provided in the Project5 resource documents. The 20pts 0pts reduce( ) method is Full Marks called in the 5/20pts constructor so that Comments all Fraction objects many bigs are automatically reduced to their lowest terms view longer description The driver class (i.e. FractionDemo.java) 10pts 0pts correctly Full Marks No Marks instantiates two 5/10 pts Fraction objects, reduced to lowest Comments terms. manybugs view longer description on your computer and then go The program The program gives correct output (i.e. two Fractions are correctly added, subtracted, 30pts0pts multiplied and Full Marks Norks divided, and the 0/30 pts double representation is Comments no output correctly implemented) view longer description 77 // Returns the new Fraction object 78 public Fraction multiply(Fraction f2) 78publicFractionmultiply79{80// Local variables for the new numerator and new denominator 81 int newNum, newDenom; 82// Get the new numerator by multiplying the two numerators newNum =( this getNum()f2getNum()); 86 // Get the new denominator by multiplying the two denominators newDenom = this getDenom()f2getDenom(); // Call constructor to instantiate the new Fraction \} return new Fraction (newNum, newDenom); 92 93// tostring to format how to display all fractions 94 public String tostring() 95\{ // Local string variable to format the fraction String strfraction; if ( denom ==1 ) \{ // If denom is 1 , this is an integer strfraction ="("+ num +")"; \}) else \{ strfraction ="("+ num +"/"+ denom +")"; 3 return strfraction; \} 3 //end of Fraction class definition 9 16 / Simport statements for scanner clas 5 11 import java.util. scanner; 12 13 //Definition of Fraction class 14 class FractionDemo\{ 15 //Declaration of private data membens private int num; private int denom; //Definition of parameterized constructon public FractionDemo(int n, int d) \{ num =n; this.setDenom(d); this.reduceFraction (); this.adjustsign(); \} //Definition of setNum method that is used to set the Malue of num variable public void setNum (int n){ num =n; \} //Definition of setNum method that is used to set the walue of denom variable public void setDenom(int d) \{ //If condition to check if the value of denominaton is zeno if (d!=0) \{ denom =d \} l/if value is zero reseting the value to 1 and printing message to screen else \{ System.out.println("For Fraction: "+this.tostring()+ +:"; System.out.println("Denominator cannot be zero; denominaton value is being reset to one"); denom =1 System.out.println("The Fraction is now: "+ this.tostring())): \} \} //Definition of getter method for num public int getNum()\{ Fraction res = new Fraction (newNum, newDenom); // reducing the resulting fraction into simplest form res.reduceFraction( ); return res; 3 public Fraction substract(Fraction F2) \{ int newNum, newDenom; int gcd=gcd( this. denom, F2.denom ); // Denominator of resulting fraction would be the LCM of both denominators // finding LCM of both denominator using GCD //LCMGCD=ab newDenom =( this. denom F2. denom )/gcd; I/ Changing the fractions to have same denominator // Numerator of the resulting fraction can now be calculated newNum =(this.num)( newDenom/this. denom )(F2num)( newDenom/F2. denom ); Fraction res = new Fraction(newNum, newDenom) ; //reducing the resulting fraction into simplest form res.reducefraction(); return res; \} //definition of getDouble method that returns the floating point value of the fraction public double getDouble() \{ double res =( double)this.num / (double) this. denom; return res; \} \} All integer values are positive: Enter the numerator of the first fraction: 5 Enter the denominator of the first fraction: 8 Enter the numerator of the second fraction: 3 Enter the denominator of the second fraction: 10 f1==(5/8) f2==(3/10) (5/8)==0.6250 (3/10)==0.3000 (5/8)(3/10)==(3/16) (5/8)/(3/10)==(25/12) (5/8)+(3/10)=(37/40) (5/8)(3/10)==(13/40) All integer values are negative: - When both numerator and denominator are negative, the Fraction is positive Enter the numerator of the first fraction: 5 Enter the denominator of the first fraction: 8 Enter the numerator of the second fraction: 3 Enter the denominator of the second fraction: 10 f1 =(5/8) f2 =(3/10) (5/8)==0.6250 (3/10)==0.3000 (5/8)(3/10)==(3/16) (5/8)/(3/10)==(25/12) (5/8)+(3/10)==(37/40) (5/8)(3/10)=(13/40) Both Fraction objects are negative: Enter the numerator of the first fraction: 5 Enter the denominator of the first fraction: 8 Enter the numerator of the second fraction: 3 Enter the denominator of the second fraction: 10 f1==(5/8) f2==(3/10) (5/8)==0.6250 (3/10)==0.3000 (5/8)(3/10)==(3/16) (5/8)/(3/10)==(25/12) (5/8)+(3/10)==(37/40) (5/8)(3/10)==(13/40)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

a. What are S, F, and P? Pg45

Answered: 1 week ago