How to create a String Array and link it to a Grade array
        Posted  
        
            by 
                user1861544
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user1861544
        
        
        
        Published on 2012-11-28T22:59:40Z
        Indexed on 
            2012/11/28
            23:03 UTC
        
        
        Read the original article
        Hit count: 246
        
I have a project that I need to create 2 Arrays, one to hold Student Names and one to hold Student Scores. The user inputs the size of the array, and the array needs to be sorted using BubbleSort (putting the high scores at the top). I have started the project, created the first array for scores, I have successfully done bubble sort and sorted the grades. Now I can't figure out how to make an array for Names, and once I do how do I make the names array correspond to the Grades array BubbleSort?
Here is the code I have so far.
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? " );
int[]GradeArray = new int[UserIn.nextInt()];
for( int i=0 ; i<GradeArray.length ; i++ ) 
{
System.out.print( "Enter Grade for Student " + (i+1) + ": " );
GradeArray[i] = UserIn.nextInt();
}
bubbleSort(GradeArray);
for( int i : GradeArray ) System.out.println( i );
System.out.println();
}
}
private static void bubbleSort(int[]GradeArray){
int n = GradeArray.length;
int temp = 0;
String temp2;
for(int i=0; i<n; i++){
 for(int 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;
   }
  }
 }
}
}
Also how do I change the grades to Double? I started with Int and when I try to change everything to double I get an error saying "Found Double, expected Int".
© Stack Overflow or respective owner