so i need help on Modifying the source code to sort on the Title (in ascending order) and display the book title, comma space, author’s first name, comma space, author’s last name. Ensure all your variable names are appropriately named.
and i also need help Modifying the source code to display and sort on the Title in reverse
any help would be welcome
{
// Declarations
Book[] bkarray = new Book[4];
String firstName, lastName, title;
BufferedReader in=new BufferedReader(
new InputStreamReader(System.in));
// Loop to get information on the 5 books
for (int i=0; i<4; i++)
{
// Prompts user questions
System.out.print("Please enter author #"+(i+1)+
"'s first name: ");
firstName = in.readLine();
System.out.print("Please enter author #"+(i+1)+
"'s last name: ");
lastName = in.readLine();
System.out.print("Please enter author #"+(i+1)+
"'s book title: ");
title = in.readLine();
bkarray[i] = new Book();
bkarray[i].setFirstName(firstName);
bkarray[i].setLastName(lastName);
bkarray[i].setTitle(title);
}
// Loop to sort the books by Last Name
for (int i=1; i<4; i++)
{
int j=i;
String tempLN = bkarray[i].getTitle();
Book tempBk = bkarray[i];
while ((j>0) &&
(bkarray[j-1].getTitle().compareTo(tempLN)>0))
{
bkarray[j] = bkarray[j-1];
j--;
}
bkarray[j] = tempBk;
}
// Loop to Print results to the screen
for (int i=0; i<4; i++)
{
System.out.print(bkarray[i].getLastName()+", ");
System.out.print(bkarray[i].getFirstName()+", ");
System.out.println(bkarray[i].getTitle());
}
}
}