I have a project that I need to create 2 arrays, one for storing student names and one for holding student points. The user enters the size of the array, and the array must be sorted using BubbleSort (by placing the upper bounds at the top). I started the project, created the first array for the evaluation, I successfully sorted the bubbles and sorted the estimates. Now I can’t figure out how to create an array for names, and as soon as I do, how to make an array of names match the Grades BubbleSort array?
Here is the code I have.
import java.util.Scanner; public class Grades { public static void main(String[]args){ { Scanner GradeIn = new Scanner(System.in); Scanner NameIn = new Scanner(System.in); System.out.print( "How many students are there? " ); int[]GradeArray = new int[GradeIn.nextInt()]; String[]nameArray = new String[GradeIn.nextInt()]; for( int i=0 ; i<GradeArray.length ; i++ ) { System.out.print( "Enter Grade for Student " + (i+1) + ": " ); GradeArray[i] = GradeIn.nextInt(); System.out.print( "Enter Name of Student " + (i+1) + ": " ); nameArray[i] = NameIn.nextLine(); } bubbleSort(GradeArray, nameArray); for( int i : GradeArray ) System.out.println( i ); System.out.println(); } } private static void bubbleSort(int[]GradeArray, String[] nameArray){ int n = GradeArray.length; int temp = 0; String temp2; for(int i=0; i<n; i++){ for(int j=1; j<(ni);j++){ if(GradeArray[j-1]<GradeArray[j]){
Also, how do I change grades to Double? I started with Int, and when I try to change everything to double, I get the error "Found Double, expected Int".
What the professor asks for: Write a program in which the user enters the number of students, the names of students and their scores and prints the names in descending order in accordance with their ratings.
ADDITIONAL INFORMATION:
You will need two arrays. One to keep the lines. Another to conduct student grades. (Doubles)
The size of the arrays will be entered by the user.
You will have to sort the arrays in the main () method. I recommend using BubbleSort (http://www.java-examples.com/java-bubble-sort-example), but not as a separate method. TIP. When sorting an array of grades, you need to sort the array of names according to the estimates.
And finally, you must enable the (void printAnswer (String [] names)) method to print the array of names after sorting it.
source share