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;
}
}