Question
The code is in java can u just add the cleaning part mentioned in the instructions so I can use it for a heap sort
The code is in java can u just add the cleaning part mentioned in the instructions so I can use it for a heap sort later. Its a code for dividing fractions.
package test;
//return gcd public class Utility { public static int findGCD(int n, int m) { if (n % m == 0) { return m; } return findGCD(m, n % m); } }
//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; } }
bubble sort logic - Bing ima Page mv: WebClass 5 Program 2.pdf x + - X & 1 E Page mv: WebClass Index of /LECTURES fibonacci code java - Bing ir O c 5182.00.csun.edu/LECTURES/Wk3/Program%202.pdf of 1 1 0 - + Fit to page Page view A Read aloud Addnates 6 Program: Sort in Fraction, Due on Saturday Feb 15, 2020 30 points Please followine the following instructions before turning in your LISR 1. Your USB will have a label from outside under Your_LastName_FirstName 2. Inside your USR there is a FOLDFR under the name: Yourl AstName_First Name_P2. 3 Inside the above foluer, A. There are only the source codes. There will be Nn files with suffix dass b. The first line in each file must bear your full name alter 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 a sample of the instructions (caller in Test.java: Strings ="2,3/4, 1/16, 23/2, 22/4...15/2,"://code to read from keyboard via Scanner S = Utility.cleans System.out.println("clearel' +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 Practions="tabili obj bubbleSPC); // sort array using bubble, insertion, or selection System.out.println("Fractions in increasing order-' + obj): 6 Outline of class Sort5P- a. Name of class is "Sort" followed by your initials in upper coses. b. There are 2 attributes: (Note: You should not add any extra attributes) String SSP:/ame of string started with ":" followed by your initials in upper cases. Fraction SP:// name 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. O Type here to search A D 4x of 20/2020Step 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