I have an assignment to create 2 arrays. One holding Student names, one holding their grades. They then have to be sorted using BubbleSort, so that their grades are in descending order. I have created the first part of it, that allows me to put in their grades, and I was able to succesfully sort it using BubbleSort. I ran into a problem when I realized the professor wanted it as Doubles (I had previously had it set as Ints) and now even though I think I changed all instances of Int to Double I'm still getting an error saying found Int, expected Double.
code is as follows.
import java.util.Scanner;
public class Grades {
public static void main(String[]args){
{
Scanner UserIn = new Scanner(System.in);
System.out.print( "How many students are there? " );
double[] GradeArray = new double[UserIn.nextDouble()];
for( double i=0 ; i<GradeArray.length ; i++ )
{
System.out.print( "Enter Grade for Student " + (i+1) + ": " );
GradeArray[i] = UserIn.nextDouble();
}
bubbleSort(GradeArray);
for( double i : GradeArray ) System.out.println( i );
System.out.println();
}
}
private static void bubbleSort(double[]GradeArray){
double n = GradeArray.length;
double temp = 0;
for(double i=0; i<n; i++){
for(double j=1; j<(n-i);j++){
if(GradeArray[j-1]<GradeArray[j]){
//swap
temp=GradeArray[j-1];
GradeArray[j-1]=GradeArray[j];
GradeArray[j]=temp;
}
}
}
}
}
I have not started the String array for the students names yet, as I do not know how to sort that to correspond with the BubbleSort on the grades.
Any help would be appreciated.