Beginner in Java using an old textbook and Head First: Java books to figure some stuff out.
I have three arrays all parallel. I need to be able to sort by Title, Author, or Page Count based on user selection. I can sort one using Arrays.sort()
but I'm getting hung up on how to sort the other two arrays to correspond to the new sorted one.
Say I sort the BookTitle
array, but I'm going to need to display the proper author and page count of its respective arrays and I'm stumped.
do
{
entry = JOptionPane.showInputDialog(null,
"Enter your sort preference: \n" +
"T = Sort by TITLE\n" +
"A = Sort by AUTHOR\n" +
"P = Sort by PAGE Count");
c = entry.charAt(0);
switch (c)
{
case 't':
case 'T':
Arrays.sort(BookTitle);
for (int x = 0; x < BookTitle.length; x++)
{
msg += ("Title: " + BookTitle[x] + "\n");
}
JOptionPane.showMessageDialog(null, msg);
isValid = true;
break;
case 'a':
case 'A':
isValid = true;
break;
case 'p':
case 'P':
isValid = true;
break;
default:
JOptionPane.showMessageDialog(null, "Invalid entry");
break;
}
} while (isValid == false);