# Sorting parallel arrays project - HELP!

• April 12th, 2013, 09:25 AM
timisaballer23
Sorting parallel arrays project - HELP!
I need the names of the card, rates, and amount owed to print out. however im not sure how to do this. please help. been stuck for too long.
the class that needs work is the selectionSort class.

Code Java:

```  public class sortparallelarrays {   public static void main (String [] args) { String [] card = {"Disney Rewards" , "Amazon Rewards", "Chase Sapphire", "Marriott Rewards"}; double [] rates = {14.24, 13.24, 15.24, 14.20}; double [] owed = {4500.00, 1300.10, 3200.80, 775.00}; double amount;     displayHeader();   selectionSort(card, rates, owed);     }   public static void displayHeader() { System.out.printf("%8s %9s %10s %16s \n" , "Card", "Rate of Interest", "Amount owed", "In one year, you'll owe");   System.out.println("===================================================================");     }   public static void displayValues(String [] c, double [] r, double [] owed) { System.out.printf("%8s %18s %25s \n", c, r, owed);   }   public static void selectionSort(String [] card, double [] rates, double [] owed) { for (int i=0; i< rates.length; i++) { for (int j=i+1; j< rates.length; j++){ if (rates[j] > rates[i]){ double temp = rates[i]; rates[i] = rates[j]; rates[j] = temp;   String temppp = card[i]; card[i] = card[j]; card[j] = temppp; double tempppp = owed[i]; owed[i] = owed[j]; owed[j] = tempppp; } } } for (int i=0; i<rates.length; i++){ System.out.println(); System.out.print( rates[i]);   }   }     }```
• April 12th, 2013, 09:49 AM
Norm
Re: Sorting parallel arrays project - HELP!
What does the posted code do wrong? can you print the program's output that shows what the problem is?

This method is useful for printing out the contents of arrays:
Code :

`System.out.println("an ID "+ java.util.Arrays.toString(theArrayName));`
• April 12th, 2013, 09:53 AM
timisaballer23
Re: Sorting parallel arrays project - HELP!
The posted code only will return this

Card Rate of Interest Amount owed In one year, you'll owe
================================================== =================

15.24
14.24
14.2
13.24

however, i need it to return the card names, and amount owed.
• April 12th, 2013, 10:04 AM
Norm
Re: Sorting parallel arrays project - HELP!
To print the contents of the other arrays, you need to access elements in those arrays in the print/println/printf method just like you are accessing the element in the array whose values are now printing.

You could build a String to print out by concatenating separate array elements with +" "+ between them
or use the printf() method which will format the line for you.