SlideShare a Scribd company logo
1 of 14
Download to read offline
...............
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 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();
}
}
.....................
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 {
float[] a1 = Arrays.copyOf(a,a.length);
FloatArrays.bubbleSort(a1);
compare(a,a1);
float[] b1 = Arrays.copyOf(b,b.length);
FloatArrays.bubbleSort(b1);
compare(b,b1);
}
/**
* Tests the Task 2 implementation.
*
* @throws Exception
* if an error occurs
*/
@Test
public void test2() throws Exception {
float[] a1 = Arrays.copyOf(a,a.length);
FloatArrays.selectionSort(a1);
compare(a,a1);
float[] b1 = Arrays.copyOf(b,b.length);
FloatArrays.selectionSort(b1);
compare(b,b1);
}
/**
* Tests the Task 3 implementation.
*
* @throws Exception
* if an error occurs
*/
@Test
public void test3() throws Exception {
float[] a1 = Arrays.copyOf(a,a.length);
FloatArrays.quickSort(a1);
compare(a,a1);
float[] b1 = Arrays.copyOf(b,b.length);
FloatArrays.quickSort(b1);
compare(b,b1);
}
/**
* 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);
}
}
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 {
float[] a1 = Arrays.copyOf(a,a.length);
FloatArrays.bubbleSort(a1);
compare(a,a1);
float[] b1 = Arrays.copyOf(b,b.length);
FloatArrays.bubbleSort(b1);
compare(b,b1);
}
/**
* Tests the Task 2 implementation.
*
* @throws Exception
* if an error occurs
*/
@Test
public void test2() throws Exception {
float[] a1 = Arrays.copyOf(a,a.length);
FloatArrays.selectionSort(a1);
compare(a,a1);
float[] b1 = Arrays.copyOf(b,b.length);
FloatArrays.selectionSort(b1);
compare(b,b1);
}
/**
* Tests the Task 3 implementation.
*
* @throws Exception
* if an error occurs
*/
@Test
public void test3() throws Exception {
float[] a1 = Arrays.copyOf(a,a.length);
FloatArrays.quickSort(a1);
compare(a,a1);
float[] b1 = Arrays.copyOf(b,b.length);
FloatArrays.quickSort(b1);
compare(b,b1);
}
/**
* 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
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".

More Related Content

Similar to --------------- FloatArrays-java - ckage csi213-lab05-import java-u.pdf

Autoboxing and unboxing
Autoboxing and unboxingAutoboxing and unboxing
Autoboxing and unboxingGeetha Manohar
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentalsHCMUTE
 
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfinfo309708
 
Chap2 class,objects contd
Chap2 class,objects contdChap2 class,objects contd
Chap2 class,objects contdraksharao
 
More topics on Java
More topics on JavaMore topics on Java
More topics on JavaAhmed Misbah
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)Chhom Karath
 
object oriented programming java lectures
object oriented programming java lecturesobject oriented programming java lectures
object oriented programming java lecturesMSohaib24
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1Todor Kolev
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1Todor Kolev
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1Todor Kolev
 
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Sunil Kumar Gunasekaran
 
Java Programs
Java ProgramsJava Programs
Java Programsvvpadhu
 
Learning Java 1 – Introduction
Learning Java 1 – IntroductionLearning Java 1 – Introduction
Learning Java 1 – Introductioncaswenson
 

Similar to --------------- FloatArrays-java - ckage csi213-lab05-import java-u.pdf (20)

Autoboxing and unboxing
Autoboxing and unboxingAutoboxing and unboxing
Autoboxing and unboxing
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
Ast transformation
Ast transformationAst transformation
Ast transformation
 
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
 
3 j unit
3 j unit3 j unit
3 j unit
 
Chap2 class,objects contd
Chap2 class,objects contdChap2 class,objects contd
Chap2 class,objects contd
 
Java Unit 1 Project
Java Unit 1 ProjectJava Unit 1 Project
Java Unit 1 Project
 
unit-3java.pptx
unit-3java.pptxunit-3java.pptx
unit-3java.pptx
 
More topics on Java
More topics on JavaMore topics on Java
More topics on Java
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
 
object oriented programming java lectures
object oriented programming java lecturesobject oriented programming java lectures
object oriented programming java lectures
 
Java2
Java2Java2
Java2
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
 
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
 
JAVA LESSON-02.pptx
JAVA LESSON-02.pptxJAVA LESSON-02.pptx
JAVA LESSON-02.pptx
 
What is new in Java 8
What is new in Java 8What is new in Java 8
What is new in Java 8
 
Java Programs
Java ProgramsJava Programs
Java Programs
 
Learning Java 1 – Introduction
Learning Java 1 – IntroductionLearning Java 1 – Introduction
Learning Java 1 – Introduction
 

More from AdrianEBJKingr

1- Answer the following characteristics for Chytridiomycota Fungi- A-.pdf
1- Answer the following characteristics for Chytridiomycota Fungi- A-.pdf1- Answer the following characteristics for Chytridiomycota Fungi- A-.pdf
1- Answer the following characteristics for Chytridiomycota Fungi- A-.pdfAdrianEBJKingr
 
1- A TIPS has a coupon of 7-- paid semiannually- The current rate of i.pdf
1- A TIPS has a coupon of 7-- paid semiannually- The current rate of i.pdf1- A TIPS has a coupon of 7-- paid semiannually- The current rate of i.pdf
1- A TIPS has a coupon of 7-- paid semiannually- The current rate of i.pdfAdrianEBJKingr
 
1- A General Right to Privacy was written explicitly into the US Const.pdf
1- A General Right to Privacy was written explicitly into the US Const.pdf1- A General Right to Privacy was written explicitly into the US Const.pdf
1- A General Right to Privacy was written explicitly into the US Const.pdfAdrianEBJKingr
 
1- A business has the following information for the year- Determine th.pdf
1- A business has the following information for the year- Determine th.pdf1- A business has the following information for the year- Determine th.pdf
1- A business has the following information for the year- Determine th.pdfAdrianEBJKingr
 
1- -8 points- Write a MIPS code to compute the factorial of a positive.pdf
1- -8 points- Write a MIPS code to compute the factorial of a positive.pdf1- -8 points- Write a MIPS code to compute the factorial of a positive.pdf
1- -8 points- Write a MIPS code to compute the factorial of a positive.pdfAdrianEBJKingr
 
1- (Aggregates) Consider an economy that is in below full employment e.pdf
1- (Aggregates) Consider an economy that is in below full employment e.pdf1- (Aggregates) Consider an economy that is in below full employment e.pdf
1- (Aggregates) Consider an economy that is in below full employment e.pdfAdrianEBJKingr
 
1- (3 polats) O Suppose that A add B are ladepedbet ewnts- Furthemore-.pdf
1- (3 polats) O Suppose that A add B are ladepedbet ewnts- Furthemore-.pdf1- (3 polats) O Suppose that A add B are ladepedbet ewnts- Furthemore-.pdf
1- (3 polats) O Suppose that A add B are ladepedbet ewnts- Furthemore-.pdfAdrianEBJKingr
 
-The following information applies to the questions displayed below- O.pdf
-The following information applies to the questions displayed below- O.pdf-The following information applies to the questions displayed below- O.pdf
-The following information applies to the questions displayed below- O.pdfAdrianEBJKingr
 
-NYP-- New York Paper Co-- is using its financial results for August 2.pdf
-NYP-- New York Paper Co-- is using its financial results for August 2.pdf-NYP-- New York Paper Co-- is using its financial results for August 2.pdf
-NYP-- New York Paper Co-- is using its financial results for August 2.pdfAdrianEBJKingr
 
-Java lang- Q3 (10)- A program creates a queue- The program takes arra.pdf
-Java lang- Q3 (10)- A program creates a queue- The program takes arra.pdf-Java lang- Q3 (10)- A program creates a queue- The program takes arra.pdf
-Java lang- Q3 (10)- A program creates a queue- The program takes arra.pdfAdrianEBJKingr
 
-2-Cyanide is a highly fast-acting poison- In fact- it was developed a.pdf
-2-Cyanide is a highly fast-acting poison- In fact- it was developed a.pdf-2-Cyanide is a highly fast-acting poison- In fact- it was developed a.pdf
-2-Cyanide is a highly fast-acting poison- In fact- it was developed a.pdfAdrianEBJKingr
 
-begin{tabular}{l-l} cHALlenge -- ACriviry -end{tabular} 4-3-1- Confid.pdf
-begin{tabular}{l-l} cHALlenge -- ACriviry -end{tabular} 4-3-1- Confid.pdf-begin{tabular}{l-l} cHALlenge -- ACriviry -end{tabular} 4-3-1- Confid.pdf
-begin{tabular}{l-l} cHALlenge -- ACriviry -end{tabular} 4-3-1- Confid.pdfAdrianEBJKingr
 
---BUS-- public class Bus { String busIdentifier- String driverName- d.pdf
---BUS-- public class Bus { String busIdentifier- String driverName- d.pdf---BUS-- public class Bus { String busIdentifier- String driverName- d.pdf
---BUS-- public class Bus { String busIdentifier- String driverName- d.pdfAdrianEBJKingr
 
-10 points- For each of the Regular Expression- draw FA recognizing th.pdf
-10 points- For each of the Regular Expression- draw FA recognizing th.pdf-10 points- For each of the Regular Expression- draw FA recognizing th.pdf
-10 points- For each of the Regular Expression- draw FA recognizing th.pdfAdrianEBJKingr
 
--What is wrong with this C++ program- -- # include iostream using nam.pdf
--What is wrong with this C++ program- -- # include iostream using nam.pdf--What is wrong with this C++ program- -- # include iostream using nam.pdf
--What is wrong with this C++ program- -- # include iostream using nam.pdfAdrianEBJKingr
 
-10 points- Construct minimized DFA accepting language represented by.pdf
-10 points- Construct minimized DFA accepting language represented by.pdf-10 points- Construct minimized DFA accepting language represented by.pdf
-10 points- Construct minimized DFA accepting language represented by.pdfAdrianEBJKingr
 
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdfAdrianEBJKingr
 
--kindly help---Explain what happens when the PUSHA instruction execut.pdf
--kindly help---Explain what happens when the PUSHA instruction execut.pdf--kindly help---Explain what happens when the PUSHA instruction execut.pdf
--kindly help---Explain what happens when the PUSHA instruction execut.pdfAdrianEBJKingr
 
1)What is the most important benefit you believe students get from the.pdf
1)What is the most important benefit you believe students get from the.pdf1)What is the most important benefit you believe students get from the.pdf
1)What is the most important benefit you believe students get from the.pdfAdrianEBJKingr
 

More from AdrianEBJKingr (20)

1- Answer the following characteristics for Chytridiomycota Fungi- A-.pdf
1- Answer the following characteristics for Chytridiomycota Fungi- A-.pdf1- Answer the following characteristics for Chytridiomycota Fungi- A-.pdf
1- Answer the following characteristics for Chytridiomycota Fungi- A-.pdf
 
1- A TIPS has a coupon of 7-- paid semiannually- The current rate of i.pdf
1- A TIPS has a coupon of 7-- paid semiannually- The current rate of i.pdf1- A TIPS has a coupon of 7-- paid semiannually- The current rate of i.pdf
1- A TIPS has a coupon of 7-- paid semiannually- The current rate of i.pdf
 
1- A General Right to Privacy was written explicitly into the US Const.pdf
1- A General Right to Privacy was written explicitly into the US Const.pdf1- A General Right to Privacy was written explicitly into the US Const.pdf
1- A General Right to Privacy was written explicitly into the US Const.pdf
 
1- A business has the following information for the year- Determine th.pdf
1- A business has the following information for the year- Determine th.pdf1- A business has the following information for the year- Determine th.pdf
1- A business has the following information for the year- Determine th.pdf
 
1- -8 points- Write a MIPS code to compute the factorial of a positive.pdf
1- -8 points- Write a MIPS code to compute the factorial of a positive.pdf1- -8 points- Write a MIPS code to compute the factorial of a positive.pdf
1- -8 points- Write a MIPS code to compute the factorial of a positive.pdf
 
1- (Aggregates) Consider an economy that is in below full employment e.pdf
1- (Aggregates) Consider an economy that is in below full employment e.pdf1- (Aggregates) Consider an economy that is in below full employment e.pdf
1- (Aggregates) Consider an economy that is in below full employment e.pdf
 
1- (3 polats) O Suppose that A add B are ladepedbet ewnts- Furthemore-.pdf
1- (3 polats) O Suppose that A add B are ladepedbet ewnts- Furthemore-.pdf1- (3 polats) O Suppose that A add B are ladepedbet ewnts- Furthemore-.pdf
1- (3 polats) O Suppose that A add B are ladepedbet ewnts- Furthemore-.pdf
 
-The following information applies to the questions displayed below- O.pdf
-The following information applies to the questions displayed below- O.pdf-The following information applies to the questions displayed below- O.pdf
-The following information applies to the questions displayed below- O.pdf
 
-NYP-- New York Paper Co-- is using its financial results for August 2.pdf
-NYP-- New York Paper Co-- is using its financial results for August 2.pdf-NYP-- New York Paper Co-- is using its financial results for August 2.pdf
-NYP-- New York Paper Co-- is using its financial results for August 2.pdf
 
-Java lang- Q3 (10)- A program creates a queue- The program takes arra.pdf
-Java lang- Q3 (10)- A program creates a queue- The program takes arra.pdf-Java lang- Q3 (10)- A program creates a queue- The program takes arra.pdf
-Java lang- Q3 (10)- A program creates a queue- The program takes arra.pdf
 
-2-Cyanide is a highly fast-acting poison- In fact- it was developed a.pdf
-2-Cyanide is a highly fast-acting poison- In fact- it was developed a.pdf-2-Cyanide is a highly fast-acting poison- In fact- it was developed a.pdf
-2-Cyanide is a highly fast-acting poison- In fact- it was developed a.pdf
 
-23-.pdf
-23-.pdf-23-.pdf
-23-.pdf
 
-begin{tabular}{l-l} cHALlenge -- ACriviry -end{tabular} 4-3-1- Confid.pdf
-begin{tabular}{l-l} cHALlenge -- ACriviry -end{tabular} 4-3-1- Confid.pdf-begin{tabular}{l-l} cHALlenge -- ACriviry -end{tabular} 4-3-1- Confid.pdf
-begin{tabular}{l-l} cHALlenge -- ACriviry -end{tabular} 4-3-1- Confid.pdf
 
---BUS-- public class Bus { String busIdentifier- String driverName- d.pdf
---BUS-- public class Bus { String busIdentifier- String driverName- d.pdf---BUS-- public class Bus { String busIdentifier- String driverName- d.pdf
---BUS-- public class Bus { String busIdentifier- String driverName- d.pdf
 
-10 points- For each of the Regular Expression- draw FA recognizing th.pdf
-10 points- For each of the Regular Expression- draw FA recognizing th.pdf-10 points- For each of the Regular Expression- draw FA recognizing th.pdf
-10 points- For each of the Regular Expression- draw FA recognizing th.pdf
 
--What is wrong with this C++ program- -- # include iostream using nam.pdf
--What is wrong with this C++ program- -- # include iostream using nam.pdf--What is wrong with this C++ program- -- # include iostream using nam.pdf
--What is wrong with this C++ program- -- # include iostream using nam.pdf
 
-10 points- Construct minimized DFA accepting language represented by.pdf
-10 points- Construct minimized DFA accepting language represented by.pdf-10 points- Construct minimized DFA accepting language represented by.pdf
-10 points- Construct minimized DFA accepting language represented by.pdf
 
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
 
--kindly help---Explain what happens when the PUSHA instruction execut.pdf
--kindly help---Explain what happens when the PUSHA instruction execut.pdf--kindly help---Explain what happens when the PUSHA instruction execut.pdf
--kindly help---Explain what happens when the PUSHA instruction execut.pdf
 
1)What is the most important benefit you believe students get from the.pdf
1)What is the most important benefit you believe students get from the.pdf1)What is the most important benefit you believe students get from the.pdf
1)What is the most important benefit you believe students get from the.pdf
 

Recently uploaded

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 

Recently uploaded (20)

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 

--------------- FloatArrays-java - ckage csi213-lab05-import java-u.pdf

  • 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 {
  • 8. float[] a1 = Arrays.copyOf(a,a.length); FloatArrays.bubbleSort(a1); compare(a,a1); float[] b1 = Arrays.copyOf(b,b.length); FloatArrays.bubbleSort(b1); compare(b,b1); } /** * Tests the Task 2 implementation. * * @throws Exception * if an error occurs */ @Test public void test2() throws Exception { float[] a1 = Arrays.copyOf(a,a.length); FloatArrays.selectionSort(a1); compare(a,a1); float[] b1 = Arrays.copyOf(b,b.length); FloatArrays.selectionSort(b1); compare(b,b1);
  • 9. } /** * Tests the Task 3 implementation. * * @throws Exception * if an error occurs */ @Test public void test3() throws Exception { float[] a1 = Arrays.copyOf(a,a.length); FloatArrays.quickSort(a1); compare(a,a1); float[] b1 = Arrays.copyOf(b,b.length); FloatArrays.quickSort(b1); compare(b,b1); } /** * Compares the two specified {@code float} arrays. * * @param a * a {@code float} array * @param b
  • 10. * 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); } } 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. *
  • 11. * @throws Exception * if an error occurs */ @Test public void test1() throws Exception { float[] a1 = Arrays.copyOf(a,a.length); FloatArrays.bubbleSort(a1); compare(a,a1); float[] b1 = Arrays.copyOf(b,b.length); FloatArrays.bubbleSort(b1); compare(b,b1); } /** * Tests the Task 2 implementation. * * @throws Exception * if an error occurs */ @Test public void test2() throws Exception { float[] a1 = Arrays.copyOf(a,a.length); FloatArrays.selectionSort(a1);
  • 12. compare(a,a1); float[] b1 = Arrays.copyOf(b,b.length); FloatArrays.selectionSort(b1); compare(b,b1); } /** * Tests the Task 3 implementation. * * @throws Exception * if an error occurs */ @Test public void test3() throws Exception { float[] a1 = Arrays.copyOf(a,a.length); FloatArrays.quickSort(a1); compare(a,a1); float[] b1 = Arrays.copyOf(b,b.length); FloatArrays.quickSort(b1); compare(b,b1); } /**
  • 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".