Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8911045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:50:35+00:00 2026-06-15T03:50:35+00:00

I have a project that I need to create 2 Arrays, one to hold

  • 0

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 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<(n-i);j++){

  if(GradeArray[j-1]<GradeArray[j]){
   //swap
   temp=GradeArray[j-1];
   GradeArray[j-1]=GradeArray[j];
   GradeArray[j]=temp;

    temp2=nameArray[j-1];
    nameArray[j=1]=nameArray[j];
    nameArray[j]=temp2;


   }
  }
 }
}
}

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”.

What the Professor is asking for:
Write a program that prompts the user to enter the number of students, the students’ names, and their scores, and prints the names in decreasing order according to their scores.

ADDITIONAL INFO:

You will need two arays. One to hold strings. Another to hold the students’ scores. (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 the BubbleSort (http://www.java-examples.com/java-bubble-sort-example) but not as a separate method. HINT: While sorting the grades array, you will need to sort the names array according to the grades.

And finally, you should include a method (void printAnswer(String [] names)) to print out the names array after it has been sorted.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:50:36+00:00Added an answer on June 15, 2026 at 3:50 am

    Make a custom object. This is the entire idea of object oriented programming. You don’t have a name and a grade, you have a Student who has a name and a grade. Then you manipulate the student in whatever way you see fit.

    public class Student {
        private String name;
        private int grade;
    
        public Student(String name, int grade) {
            this.name = name;
            this.grade = grade;
        }
    
        public String getName() {
            return name;
        }
        public int getGrade() {
            return grade;
        }
    }
    

    Then where you have

    int[]GradeArray = new int[UserIn.nextInt()];
    

    Do this instead:

    Student[] studentArray = new Student[UserIn.nextInt()];
    

    I leave the rest of the changes as an exercise for you to get used to how it should work. Though, remember that a Student[] is full of null, as you read in the data, you have to create a new Student(name, grade) each time.


    Alternate solution

    The above is the correct way to do this. Do not learn anything from the below answer, becuase it defeats the entire purpose of learning Java. I would email the professor if the above solution is acceptable.

    That being said, as you do each grade swap, you could do exactly the same swap in the String name array, i.e.

    // change method signature
    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<(n-i);j++){
    
          if(gradeArray[j-1]<gradeArray[j]){
            //swap
            temp=gradeArray[j-1];
            gradeArray[j-1]=gradeArray[j];
            gradeArray[j]=temp;
    
            // New code begin
            temp2=nameArray[j-1];
            nameArray[j-1]=nameArray[j];
            nameArray[j]=temp2;
            // New code end
          }
        }
      }
    }
    

    Again, DO NOT DO THIS IN THE REAL WORLD ONCE YOU ARE NO LONGER IN SCHOOL. It is MUCH SLOWER and much more confusing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a job portal website project in that i need to signup user
I have a project that necessarily spans several databases. One database has tables: CREATE
I have a maven project that contains a certain api I need to use
We have a big C++ project that's compiled as native unmanaged code. We need
I need to have an at-home project now that I'm working on Python/Django at
I have projects that need to be build with a specific version of the
i have a big solution containing that much projects..i need to find a specific
I have a project that may be started on local machine with ./manage.py runserver
I have a project that I have divided quite aggressively into different layers. I
I have a project that using some third-party libraries. My questions is how to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.