Final answer:
The task involves creating a Java code section for Bubble Sort, which includes printing a section header, initializing an array called StudentGrades with provided grades, and creating a method SortArrayDescBS() to sort the array using Bubble Sort in descending order.
Step-by-step explanation:
Bubble Sort in Java
To address Section 1 of your assignment, we'll first add a comment in the code indicating the start of the section and then use System.out.println to print "Section 1 – Bubble Sort ****" followed by a blank line. We will create an array called StudentGrades and populate it with the grades provided. Finally, we'll create a method named SortArrayDescBS() that will implement the Bubble Sort algorithm to sort the array in descending order.
Here's how your Java code might look:
// Section 1 - Bubble Sort
System.out.println("Section 1 – Bubble Sort ****\\");
int[] StudentGrades = {65, 95, 75, 55, 56, 90, 98, 88, 97, 78};
public void SortArrayDescBS(int[] array) {
boolean swapped;
for (int i = 0; i < array.length - 1; i++) {
swapped = false;
for (int j = 0; j < array.length - 1 - i; j++) {
if (array[j] < array[j + 1]) {
int temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
swapped = true;
}
}
if (!swapped) break;
}
}
This code block will sort the StudentGrades array in descending order using the Bubble Sort algorithm.