Question: Can you make a heapsort for fractions using the code I have for dividing fractions its in java, there are more details in the instructions.

Can you make a heapsort for fractions using the code I have for dividing fractions its in java, there are more details in the instructions.

Can you make a heapsort for fractions using the code I have

package test;

//return gcd public class Utility {

public static String clean ( String s ) { int numerator; String s1[] = s.split(", "); for(int i = 0; i

//test public class Test {

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

//fraction class public class Fraction {

int num, den;

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

//constructor with string as parameter public Fraction(String fract) { int integral,num,den; //if mixed fraction, split the string try{ String[]number = fract.split(" "); integral = Integer.parseInt(number[0]); String[] num_dun = number[1].split("/"); num = Integer.parseInt(num_dun[0]); den = Integer.parseInt(num_dun[1]); num = integral*den+num; } //if fraction is regular, catch the error and proceed with alternate code catch(NumberFormatException e) { String[] num_dun = fract.split("/"); num = Integer.parseInt(num_dun[0]); den = Integer.parseInt(num_dun[1]); } //set num , den this.num = num; this.den = den;

}

//divide fraction 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; }

//return string public String toString() { if(den==1) return num+""; else return num+"/"+den; } }

Program 3: Heap Sort on Fractions, Due on Feb 28, 2020 50 point bonus Please follow the following instructions before turning in your USB 1. Your USB will have a label from outside under YourLastName_FirstName 2. Inside your USB there is a FOLDER under the name: YourLastName_FirstName_P3. 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. 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. Conditions: You must follow the lecture in class to implement HeapSort on Fractions in order to be granted the bonus. Here is a sample of the instructions (caller) in Test.java: //read from keyboard a string such as s="2,3/4, 1/16,-2 3/2, 2 2/4,,,15/2,," //create an object such as HeapSortSP obj = new HeapSortSP(s); //sort: obj.heap SortSP(); //Print: System.out.println("Fractions in increasing order =" + obj); 6. Note: SP are the initials of your instructor. You need to replace they by yours. Program 3: Heap Sort on Fractions, Due on Feb 28, 2020 50 point bonus Please follow the following instructions before turning in your USB 1. Your USB will have a label from outside under YourLastName_FirstName 2. Inside your USB there is a FOLDER under the name: YourLastName_FirstName_P3. 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. 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. Conditions: You must follow the lecture in class to implement HeapSort on Fractions in order to be granted the bonus. Here is a sample of the instructions (caller) in Test.java: //read from keyboard a string such as s="2,3/4, 1/16,-2 3/2, 2 2/4,,,15/2,," //create an object such as HeapSortSP obj = new HeapSortSP(s); //sort: obj.heap SortSP(); //Print: System.out.println("Fractions in increasing order =" + obj); 6. Note: SP are the initials of your instructor. You need to replace they by yours

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!