Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can u fix the code so the second string fraction being divided can also be a regular fraction like 3/4 it can only handle it

can u fix the code so the second string fraction being divided can also be a regular fraction like 3/4 it can only handle it if it was a mixed fraction like 1 3/4 as well as add a bubble sort with the specifications in the second picture. image text in transcribed

image text in transcribed

this was the instructions for the first project the division image text in transcribed

and heres a clearer pic of the output

image text in transcribed

public class Utility { public static int findGCD(int n, int m) { if (n % m == 0) { return m; } return findGCD(m, n % m); } }

public class Test { public static void main(String[] args) { Fraction g=new Fraction(2,8); Fraction f= new Fraction("1 3/4"); System.out.println("Orig="+f+","+g); Fraction[]quotient_remainder=Fraction.divFract(f,g); System.out.println("After="+f+","+g); System.out.println("Quotient & Remainder="+quotient_remainder[0]+","+ quotient_remainder[1]); } }

public class Fraction {

int num, den;

public Fraction(int num, int den) { this.num = num; this.den = den; }

public Fraction(String fract) { String[]number = fract.split(" "); int integral = Integer.parseInt(number[0]); String[] num_dun = number[1].split("/"); int num = Integer.parseInt(num_dun[0]); int den = Integer.parseInt(num_dun[1]); num = integral*den+num; this.num = num; this.den = den; } public static Fraction[] divFract(Fraction f, Fraction g) { int num_div = f.num * g.den; int den_div = f.den * g.num; int gcd = Utility.findGCD(num_div, den_div); num_div/=gcd; den_div/=gcd; f.num = num_div; f.den = den_div; int quotient = num_div/den_div; int remainder = num_div % den_div; Fraction[] retValue = {new Fraction(quotient, 1), new Fraction(remainder, 1)}; return retValue; } public String toString() { if(den==1) return num+""; else return num+"/"+den; }

}

F a ny prog:17 PMode feel free to Utility.java package fractions: public class Utility Winding ged using recursion public static int findGCD(int n, int m) { ) if (n% m 0 return m: return findGCD/m, n % m): Eraction.java package fractions: public class Fraction int num, den: public Fraction(int num, int den) this num num; this. den den public Fraction(String fract) Stringnumberfract.split(""). int integral - Integer.parseInt(number[O]: String[] num dun=number[1].split("" int num= Integer.parselinum dun[0]): int den Integer.parseInt(num dun[1]: num=integral dentnum this nummum: this den-den: public static Fraction] divFract[Fraction f. Fraction ) int num_div .num .den; int den_diy-f.deng.num; performing simplyfication int ged-Utility.findGCD(num_dis, den div): num div-god; den divged: f.numnum div fdenden div int quotientnum dividen div; int remainderum div % den div; Fraction retValue = new Fraction quotient, 1) new Fraction remainder, 1): retum retValue: public String toStringo if(den=1) returnum return num" den: Output Program: Sort in Fraction, Due on Saturday Feb 15, 2020 30 points Please following the following instructions before turning in your USB 1. Your USB will have a label from outside under Your Last Name First Name 2. Inside your USB there is a FOLDER under the name: YourLastName First Name P2 3. Inside the above folder, a. There are only the source codes. There will be NO files with suffix class. b. The first line in each file must bear your full name after the double slashes // 4. Your Instructor will compile your files and run Test.class via cmd/terminal. You must be responsible to make sure your files are standard to run properly. Your instructor WILL NOT touch your files. Your instructor will make his own Test file to evaluate all students' performance 5. Here is a sample of the instructions (caller) in Test.java: Strings"2,3/4, 1/16, 23/2,2 2/4...15/2,"://code to read from keyboard via Scanner s Utility.clean(s); System.out.println("CleanOrig=1" +5+"|"); // code to create an object of Sort SortSP obj new SortSP(s); //SP are the initials of author System.out.println("init array of Fractions =" + obj); obj.bubbleSP(); // sort array using bubble, Insertion, or selection System.out.println("Fractions in increasing order =" + obj); 6. Outline of class SortSP: a. Name of class is "Sort" followed by your initials in upper cases. b. There are 2 attributes: (Note: You should not add any extra attributes) String SSP:/ame of string started with "s" followed by your initials in upper cases. Fraction() aSP:/ame of array started with "a" followed by your initials in upper cases. c methods: resetSP: to set the second attribute to be its original, (not create any unnecassary new fractions). bubbleSP: to sort the 2nd attribute in increasing order. additional methods to make the sample work 7. Note: SP are the initials of your instructor. You need to replace they by yours. three c Page mV: WebClass Program 1.pdf Program 2.pdf Program%201.pdf + Fit to page Program 1: Division in Fraction, Due on Friday Feb 7, 2020 50 points Please following the following instructions before turning in your USB 1. Your USB will have a label from outside under your_LastName_FirstName 2. Inside your USB there is a FOLDER under the name: Your_LastName_FirstName_P1. 3. Inside the above folder, a. There are only 2 or 3 files: Fraction.java and Test.java where the class Utility file can be added inside Fraction.java or to be in a separated file. There will be NO files with suffix class b. The first line in each file must bear your full name after the double slashes // 4. Your Instructor will compile your files and run Test.class via cmd/terminal. Your must be responsible to make sure your files are standard to run properly. Your instructor WILL NOT touch your files. Your instructor will make his own Test file to evaluate all students' performance. 5. Here is an example of the instructions (caller) in Test.jave: Fraction g = new Fraction(2,8); Fraction f new Fraction ("1 3/4"); System.out.println("Orig="+f+""+g): Fraction[quotient_remainder = Fraction divFract(f. g): System.out.println("After-" +f+","+B): System.out.println("Quotient & Remainder" +quotient_remanider[0] +"," +quotient_remainder[1] ); https://www.chegg.com/homework-help/questions-and-answers/code-requires-three-classes-utility Chegg. Study Textbook Solutions Expert Q&A Study Pack Pract public static Fractioni div Fract(Fraction 1, Fraction 9 int num_div f.numg.den; int den_div = f.den * g.num: //performing simplyfication Int gcd = Utility.findGCD(num_dlv, den_div); num_div/=gcd; den_dlv/=gcd; f.num = num_div: f.den - den_div; int quotient = num_div/den_div; int remainder = num_div % den_div; Fraction() retValue = (new Fraction(quotient, 1), new Fraction(remainder, 1)); return retValue; public String toString if(den==1) return num+"" else return num+"/"+den; Output Questions viewed by other students

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

Recommended Textbook for

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students also viewed these Databases questions

Question

How would we like to see ourselves?

Answered: 1 week ago