Java program that implement bubble-sort and selection-sort sorting algorithms

In today’s fast-paced academic environment, students often find themselves juggling multiple responsibilities, from attending classes and working part-time jobs to participating in extracurricular activities. The demands of modern education can be overwhelming, leaving students in search of effective solutions to manage their academic workload efficiently. One such solution is the use of Nursingpapertutors.com academic writing website. Nursingpapertutors.com academic writing website employ a cadre of experienced and knowledgeable writers who are well-versed in various academic subjects and writing styles. Nursingpapertutors.com professionals bring a wealth of expertise to the table, enabling them to produce well-researched and well-structured papers that meet the academic standards and expectations of students. Their familiarity with diverse subjects ensures that students can receive assistance across a wide spectrum of disciplines, from mathematics to literature, and from nursing to engineering.

 

1. Using Eclipse to develop the following Java program that implement bubble-sort and selection-sort sorting algorithms.

 

The following are skeletons of the bubble-sort and selection-sort algorithms:

 

Bubble sort:

 

        for (int i = 0; i < array.length; i++)

 

                    for (int j = 0; j < array.length-1; j++)

 

                                if (array[j] >= array[j+1]) {

 

                                            int temp = array[j];

 

                                            array[j] = array[j+1];

 

                                            array[j+1] = temp;

 

                                }

 

 

 

Selection sort:

 

        for (int i = 0; i < array.length-1; i++) {

 

                    int maxIndex = 0;

 

                    int j;

 

                    for (j = 1; j < array.length-i; j++)

 

                                if (array[j] > array[maxIndex]) maxIndex = j;

 

                    int temp = array[maxIndex];

 

                    array[maxIndex] = array[j-1];

 

                    array[j-1] = temp;

 

        }

 

 

 

A sorting algorithm is stable if two data items or objects with equal key values, according to which sorting is performed, do not change their precedence order in the resulting sorted array. The above two sorting algorithms may not be stable sorting algorithms. Your task in this lab assignment is to use debugging techniques to detect unstableness of these two algorithms and fix the problem to make the algorithms become stable.

 

 

 

The following are you programming task and debugging task.

 

 

 

a)      In Eclipse, create a new Java project with name cs2043lab1.

 

b)      Write the following classes and interfaces.

 

·         Define a class called “StudentRecord” as follows:

 

class StudentRecord  {

 

            private String name, int grade;

 

            public StudentRecord(String name, int grade) {this.name = name; this.grade = grade;}

 

            public int getKey() {return grade;}

 

}

 

 

 

·         Define an interface called “Sorter” as follows:

 

interface Sorter {public void sort(StudentRecord[] students);}

 

 

 

·         Define a class called “BubbleSorter” that implement sorter interface as follows:

 

class BubbleSorter implements Sorter{public void sort(StudentRecord[] students){/*implement bubble sort algorithm*/}}

 

 

 

·         Define a class called “SelectSorter” that implement sorter interface as follows:

 

class SelectSorter implements Sorter{public void sort(StudentRecord[] students){/*implement selection sort algorithm*/}}

 

 

 

·         Define the main class called “Lab1App” with main method. The main method asks the user to input data to create multiple StudentRecord objects into an array, and also asks the user to Do you need a similar assignment done for you from scratch? We have qualified writers to help you. We assure you an A+ quality paper that is free from plagiarism. Order now for an Amazing Discount!
Use Discount Code "Newclient" for a 15% Discount!

NB: We do not resell papers. Upon ordering, we do an original paper exclusively for you.