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 6841081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:55:22+00:00 2026-05-26T23:55:22+00:00

I have a class where I have to make a program that reads in

  • 0

I have a class where I have to make a program that reads in a bunch of data puts it into several different arrays. I then have to sort them but my method seems to not be working.

inside of my first for loop I have the two if statements for the two situations I would need to address. The first situation would be if the the team name comes before and the second is when the team name is the same. If the team name is the same it sorts by yards.

The name sorting works fine but when I un-comment the second statement it sorts it a order I can’t figure out.

public static void sortDatabase(int numRecords, String[] teamArr,
        int[] attemptsArr, int[] yardsArr, int[] winsArr,
        int[] loseArr)
{

    //Sort the database first according to name and then according to yards
    System.out.println("Sort the database.\n");

    int iMin;

    String teamTemp;
    int attemptTemp;
    int yardTemp;
    int winsTemp;
    int loseTemp;

    for(int i = 0; i < numRecords - 1; i++)
    {
        iMin = i;

        for(int k = i + 1; k < numRecords; k++)
        {
            int compare = teamArr[k].compareTo(teamArr[iMin]);
            if(compare < 0)
            {
                iMin = k;
            }
            else if(compare == 0 && yardsArr[k] < yardsArr[iMin])
            {                
                iMin = k;
            }

            //swap out all data
            teamTemp = teamArr[i];
            attemptTemp = attemptsArr[i];
            yardTemp = yardsArr[i];
            winsTemp = winsArr[i];
            loseTemp = loseArr[i];

            teamArr[i] = teamArr[iMin];
            attemptsArr[i] = attemptsArr[iMin];
            yardsArr[i] = yardsArr[iMin];
            winsArr[i] = winsArr[iMin];
            loseArr[i] = loseArr[iMin];

            teamArr[iMin] = teamTemp;
            attemptsArr[iMin] = attemptTemp;
            yardsArr[iMin] = yardTemp;
            winsArr[iMin] = winsTemp;
            loseArr[iMin] = loseTemp;
        }
    }
}

Also don’t comment or answer with better ways to do this or say that I should make a new class to handle all the data. Just try and answer with the sort method I am using. I am doing this for a class and have little options.

  • 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-05-26T23:55:22+00:00Added an answer on May 26, 2026 at 11:55 pm

    The bit that’s labeled //swap out all data needs to come after the for-loop that sets iMin, rather than inside it. Right now you’re doing swaps in the middle of setting iMin, and that will cause iMin to become wrong and the wrong elements to be swapped.

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

Sidebar

Related Questions

I have method in a class that I need to make sure is only
I have a Products:List<Product> class. I'd like to make it so that every time
So all I simply want to do is make a Ruby program that reads
I want to make a program in C++ that reads a file where each
I'm learning java and I have made simple program that simply reads value from
I have a program that reads and draws an SVG file in a java
This question contains java and ruby. I have a java program that I make
We have XML generated from an external program that needs to be read into
I have written a program that reads in a File object (really an XML
I have a C++ program that will read in data from a binary file

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.