Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class mlaFormat {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- String firstName[] = {"Mark", "Sue", "Jaqcueline", "Jerzy", "Temple", "Truman"}; //authors' first name
- String lastName[] = {"Haddon", "Monk Kidd", "Wilson", "Kosinski", "Grandin", "Capote"}; //authors' last name
- String bookName[] = {"The Curious Incident of the Dog in the Night-Time", "The Secret Life of Bees", "Bad Girls", "Being There", "Thinking in Pictures", "Breakfast at Tiffany's"}; //book titles
- String publisherName[] = {"Vintage", "Headline Book Publishing", "Corgi Yearling", "Black Swan", "Bloomsbury", "Vintage International"}; //publishers
- String yearPublished[] = {"2003", "2002", "1996", "1970", "1995", "1957"}; //year of publication
- mlaFormat(firstName, lastName, bookName, publisherName, yearPublished);
- } //main ends here
- static void mlaFormat(String[] firstName, String[] lastName, String[] bookName, String[] publisherName, String[] yearPublished)
- {
- for(int i=0; i<lastName.length; i++)
- {
- for(int j=1; j<(lastName.length-i); j++)
- {
- if(lastName[j-1].compareTo(lastName[j])>0)
- {
- String temp1 = firstName[j-1];
- firstName[j-1] = firstName[j];
- firstName[j] = temp1;
- String temp2 = lastName[j-1];
- lastName[j-1] = lastName[j];
- lastName[j] = temp2;
- String temp3 = bookName[j-1];
- bookName[j-1] = bookName[j];
- bookName[j] = temp3;
- String temp4 = publisherName[j-1];
- publisherName[j-1] = publisherName[j];
- publisherName[j] = temp4;
- String temp5 = yearPublished[j-1];
- yearPublished[j-1] = yearPublished[j];
- yearPublished[j] = temp5;
- } // if statement ends here
- } // inner for loop ends here
- } // outer for loop ends here
- for(int i = 0; i<firstName.length; i++)
- System.out.println(lastName[i] + ", " + firstName[i] + ". '" + bookName[i] + "', " + publisherName[i] + ", " + yearPublished[i]);
- }
- } //program ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement