Everything seems to look right, it compiles, and even runs, but the output I end up getting looks like this:

Book@6e00321, Book@5ced6f0d... etc

Why is it outputting that instead of the sorted bookList? Am I calling the method wrong, or is there something wrong in the method itself? Even worse... It seems like there is something wrong with the array declaration. I'm lost here, completely.


import java.text.NumberFormat;
import java.util.Arrays;
 
public class BookStore2 {
 
 
    public static void main(String[] args) {
 
        NumberFormat formatter = NumberFormat.getCurrencyInstance();
 
        Book[] bookList = new Book [5];
        bookList[0] = new Book("978-0-7653-6264-3", "Wizard's First Rule", "Terry Goodkind", 1994, "Tom Doherty Associates, LLC", 7.99f);
        bookList[1] = new Book("0-812-54809-4", "Stone of Tears", "Terry Goodkind", 1995, "Tom Doherty Associates, LLC", 7.99f);
        bookList[2] = new Book("0-812-55147-8", "Blood of the Fold", "Terry Goodkind", 1995, "Tom Doherty Associates, LLC", 7.99f);
        bookList[3] = new Book("0-439-15411-1", "Dracula", "Bram Stroker", 1897, "Scholastic Inc", 4.99f);
        bookList[4] = new Book("0-440-94060-5", "I Am The Cheese", "Robert Cormier", 1977, "Dell Laurel-Leaf", 5.50f);
 
        float inventoryCost = calculateTotalInventory(bookList);
        bookList = sortArray(bookList);
 
        System.out.println(Arrays.toString(bookList));
        System.out.println(formatter.format(inventoryCost));
 
        } // end Main Method
 
      public static Book[] sortArray (Book[] bookList){
 
        String[] titles = new String[bookList.length];
 
        for (int i = 0; i < bookList.length; i++){
            titles[i] = bookList[i].gettitle();
        }
 
        Arrays.sort(titles);
 
        Book[] sortedBooks = new Book [bookList.length];
 
        for (int i = 0; i < 5; i++){
            for (int k = 0; k < 5; k++){
                if (bookList[i].gettitle().equalsIgnoreCase(titles[k])){
                    sortedBooks[k] = bookList[i];
                    break;
                } // end if 
            } //end For 2
        } // end For 1
 
        return sortedBooks;
 
 } 
 
public static float calculateTotalInventory (Book[] bookList){
    float inventoryTotal = 0f;
 
        for (int f = 0; f < 5; f++){
 
              inventoryTotal = inventoryTotal + bookList[f].getprice();  
 
        } //end inventoryTotal loop
 
        return inventoryTotal;
}
 
}

Edit:

I tried running a different line of code to see if I can even get it to output anything properly, and I can by typing in:

System.out.println(bookList[0].gettitle());

So, what I'm trying to do now is get the whole array to print in the proper format. Furthermore it does look like my sorting did work because the one that printed out was Blood of the Fold, which is the first in alphabetical order. If anyone has any hints, please feel free. I'll keep updating as I figure everything out.

Holy mother of god, I got it guys!

Thread solved.