...............
FloatArrays.java :
ckage csi213.lab05;
import java.util.Arrays;
/**
* This {@code FloatArrays} class provides methods for manipulating {@code Float} arrays.
*/
public class FloatArrays {
/**
* Sorts the specified array using the bubble sort algorithm.
*
* @param a
* an {@code Float} array
*/
public static void bubbleSort(float[] a) {
System.out.println(Arrays.toString(a));
for (int last = a.length - 1; last >= 1; last--) {
// TODO: add some code here
}
System.out.println(Arrays.toString(a));
}
/**
* Sorts the specified array using the selection sort algorithm.
*
* @param a
* an {@code Float} array
* @param out
* a {@code PrintStream} to show the array at the end of each pass
*/
public static void selectionSort(float[] a) {
System.out.println(Arrays.toString(a));
for (int last = a.length - 1; last >= 1; last--) {
// TODO: add some code here
}
System.out.println(Arrays.toString(a));
}
/**
* Sorts the specified array using the quick sort algorithm.
*
* @param a
* an {@code Float} array
* @param out
* a {@code PrintStream} to show the array at the end of each pass
*/
public static void quickSort(float[] a) {
System.out.println(Arrays.toString(a));
for (int index = 1; index <= a.length - 1; index++) {
// TODO: add some code here
}
System.out.println(Arrays.toString(a));
}
/**
* The main method of the {@code FloatArrays} class.
*
* @param args
* the program arguments
*/
public static void main(String[] args) {
float[] a = { 5.3F, 3.8F, 1.2F, 2.7F, 4.99F };
bubbleSort(Arrays.copyOf(a, a.length));
System.out.println();
selectionSort(Arrays.copyOf(a, a.length));
System.out.println();
quickSort(Arrays.copyOf(a, a.length));
System.out.println();
}
}
ckage csi213.lab05;
import java.util.Arrays;
/**
* This {@code FloatArrays} class provides methods for manipulating {@code Float} arrays.
*/
public class FloatArrays {
/**
* Sorts the specified array using the bubble sort algorithm.
*
* @param a
* an {@code Float} array
*/
public static void bubbleSort(float[] a) {
System.out.println(Arrays.toString(a));
for (int last = a.length - 1; last >= 1; last--) {
// TODO: add some code here
}
System.out.println(Arrays.toString(a));
}
/**
* Sorts the specified array using the selection sort algorithm.
*
* @param a
* an {@code Float} array
* @param out
* a {@code PrintStream} to show the array at the end of each pass
*/
public static void selectionSort(float[] a) {
System.out.println(Arrays.toString(a));
for (int last = a.length - 1; last >= 1; last--) {
// TODO: add some code here
}
System.out.println(Arrays.toString(a));
}
/**
* Sorts the specified array using the quick sort algorithm.
*
* @param a
* an {@code Float} array
* @param out
* a {@code PrintStream} to show the array at the end of each pass
*/
public static void quickSort(float[] a) {
System.out.println(Arrays.toString(a));
for (int index = 1; index <= a.length - 1; index++) {
// TODO: add some code here
}
System.out.println(Arrays.toString(a));
}
/**
* The main method of the {@code FloatArr.
1. ...............
FloatArrays.java :
ckage csi213.lab05;
import java.util.Arrays;
/**
* This {@code FloatArrays} class provides methods for manipulating {@code Float} arrays.
*/
public class FloatArrays {
/**
* Sorts the specified array using the bubble sort algorithm.
*
* @param a
* an {@code Float} array
*/
public static void bubbleSort(float[] a) {
System.out.println(Arrays.toString(a));
for (int last = a.length - 1; last >= 1; last--) {
// TODO: add some code here
}
System.out.println(Arrays.toString(a));
}
/**
2. * Sorts the specified array using the selection sort algorithm.
*
* @param a
* an {@code Float} array
* @param out
* a {@code PrintStream} to show the array at the end of each pass
*/
public static void selectionSort(float[] a) {
System.out.println(Arrays.toString(a));
for (int last = a.length - 1; last >= 1; last--) {
// TODO: add some code here
}
System.out.println(Arrays.toString(a));
}
/**
* Sorts the specified array using the quick sort algorithm.
*
* @param a
* an {@code Float} array
* @param out
* a {@code PrintStream} to show the array at the end of each pass
*/
3. public static void quickSort(float[] a) {
System.out.println(Arrays.toString(a));
for (int index = 1; index <= a.length - 1; index++) {
// TODO: add some code here
}
System.out.println(Arrays.toString(a));
}
/**
* The main method of the {@code FloatArrays} class.
*
* @param args
* the program arguments
*/
public static void main(String[] args) {
float[] a = { 5.3F, 3.8F, 1.2F, 2.7F, 4.99F };
bubbleSort(Arrays.copyOf(a, a.length));
System.out.println();
selectionSort(Arrays.copyOf(a, a.length));
System.out.println();
quickSort(Arrays.copyOf(a, a.length));
4. System.out.println();
}
}
ckage csi213.lab05;
import java.util.Arrays;
/**
* This {@code FloatArrays} class provides methods for manipulating {@code Float} arrays.
*/
public class FloatArrays {
/**
* Sorts the specified array using the bubble sort algorithm.
*
* @param a
* an {@code Float} array
*/
public static void bubbleSort(float[] a) {
System.out.println(Arrays.toString(a));
for (int last = a.length - 1; last >= 1; last--) {
// TODO: add some code here
}
System.out.println(Arrays.toString(a));
}
/**
* Sorts the specified array using the selection sort algorithm.
5. *
* @param a
* an {@code Float} array
* @param out
* a {@code PrintStream} to show the array at the end of each pass
*/
public static void selectionSort(float[] a) {
System.out.println(Arrays.toString(a));
for (int last = a.length - 1; last >= 1; last--) {
// TODO: add some code here
}
System.out.println(Arrays.toString(a));
}
/**
* Sorts the specified array using the quick sort algorithm.
*
* @param a
* an {@code Float} array
* @param out
* a {@code PrintStream} to show the array at the end of each pass
*/
public static void quickSort(float[] a) {
6. System.out.println(Arrays.toString(a));
for (int index = 1; index <= a.length - 1; index++) {
// TODO: add some code here
}
System.out.println(Arrays.toString(a));
}
/**
* The main method of the {@code FloatArrays} class.
*
* @param args
* the program arguments
*/
public static void main(String[] args) {
float[] a = { 5.3F, 3.8F, 1.2F, 2.7F, 4.99F };
bubbleSort(Arrays.copyOf(a, a.length));
System.out.println();
selectionSort(Arrays.copyOf(a, a.length));
System.out.println();
quickSort(Arrays.copyOf(a, a.length));
System.out.println();
7. }
}
.....................
UnitTests.java :
package csi213.lab05;
import static org.junit.Assert.*;
import java.util.Arrays;
import org.junit.Test;
/**
* {@code UnitTests} tests the Lab 5 implementations.
*
*/
public class UnitTests {
static float[] a = { 5, 3, 1, 2, 4 };
static float[] b = { 7, 6, 5, 1, 2, 3, 4 };
/**
* Tests the Task 1 implementation.
*
* @throws Exception
* if an error occurs
*/
@Test
public void test1() throws Exception {
13. * Compares the two specified {@code float} arrays.
*
* @param a
* a {@code float} array
* @param b
* a {@code float} array
*/
protected void compare(float[] original, float[] sorted) {
assertEquals(original.length, sorted.length);
float[] temp = Arrays.copyOf(original,original.length);
Arrays.sort(temp);
for (int i = 0; i < original.length; i++)
assertEquals(temp[i], sorted[i],.001f);
}
}
PART : Completing FloatArrays.java Task 1. Complete the "bubblesort(float] a)" method so that
it sorts the specified array "a" using the bubble sort algorith. First, for a certain time limit that
you choose (e,g,, 15 minutes), try to inplenent the bubblesort (intb a) method based only on your
understanding of the algorithm. Please understand that, during each pass, bubble sort exanines
certain pairs of adjacent elements and swaps two such adjacent elenents if they are not in order.
once you finish (or after the tine linit), compare your isplementation with the Java code in the
slides. It is fine to use the code (but sone slight changes will be needed). Your code also needs to
pass the unit test naned "test10" in "unitrests.java". Task 2 . Complete the "selectionsort(float[]
a)" method so that it sorts the specified array "a" using the selection sort algorithm. For a certain
time limit that you choose (e. 9. , 15 minutes), try to implenent the "selectionsort(float] a)"
method based only on your understanding of the the algorithute. Please understand that, during
each pass, selection sort. finds the largest elenent within a certain portion in once you finish (or
after the tine li titit), compare your implenentation with the "ava code in the slides. You can use
the code from the slides (but some slight changes may be needed). Your code also needs to pass
the unit test named "test20" in "UnitTests. java". Task 3. Complete the "quicksort(floatD a)"
nethod so that it sorts the specified array "a" using the quicksort algorith. For a certain time liait
14. that you choose (e.g.. 15 minutes), try to implenent the nethod based only on your understanding
of the algoritha. Vou can use the code fron the slides (but scoe siight changes may be needed).
Your code also needs to pass the unit test named "test30" in "unitrests. java".