SlideShare ist ein Scribd-Unternehmen logo
1 von 14
Downloaden Sie, um offline zu lesen
...............
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".

Weitere ähnliche Inhalte

Ähnlich wie --------------- 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
 

Ähnlich wie --------------- 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxRosabel UA
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
The Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsThe Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsRommel Regala
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxJanEmmanBrigoli
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 

Kürzlich hochgeladen (20)

LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
The Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsThe Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World Politics
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptx
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 

--------------- 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".