return an ArrayList method

Posted by Bopeng Liu on Stack Overflow See other posts from Stack Overflow or by Bopeng Liu
Published on 2013-10-24T09:48:14Z Indexed on 2013/10/24 9:54 UTC
Read the original article Hit count: 315

Filed under:
|

This is a drive method for two other classes. which i posted here http://codereview.stackexchange.com/questions/33148/book-program-with-arraylist

I need some help for the private static ArrayList getAuthors(String authors) method. I am kind a beginner. so please help me finish this drive method. or give me some directions.

Instruction

some of the elements of the allAuthors array contain asterisks “*” between two authors names. The getAuthors method uses this asterisk as a delimiter between names to store them separately in the returned ArrayList of Strings.

import java.util.ArrayList;

public class LibraryDrive {

public static void main(String[] args) {

    String[] titles = { "The Hobbit", "Acer Dumpling", "A Christmas Carol",
            "Marley and Me", "Building Java Programs",
    "Java, How to Program" };

    String[] allAuthors = { "Tolkien, J.R.", "Doofus, Robert",
            "Dickens, Charles", "Remember, SomeoneIdont",
            "Reges, Stuart*Stepp, Marty", "Deitel, Paul*Deitel, Harvery" };

    ArrayList<String> authors = new ArrayList<String>();
    ArrayList<Book> books = new ArrayList<Book>();

    for (int i = 0; i < titles.length; i++) {
        authors = getAuthors(allAuthors[i]);
        Book b = new Book(titles[i], authors);
        books.add(b);
        authors.remove(0);
    }
    Library lib = new Library(books);
    System.out.println(lib);
    lib.sort();
    System.out.println(lib);

}

private static ArrayList<String> getAuthors(String authors) {
    ArrayList books = new ArrayList<String>();
            // need help here.
    return books;
}

}

© Stack Overflow or respective owner

Related posts about java

Related posts about arraylist