Trouble with a small library-management program
<p>I'm having major trouble piecing this together. I have basic read and write functionality. What I need is for the input from file 'Books.txt' to be checked so that:</p>

<ul>
<li>ISBN is valid</li>
<li>CopyNumber, Year and Statistics should be numeric</li>
<li>Title, Author and Publisher must contain values</li>
<li>BorrowDate must be a valid date</li>
<li>ReturnDate if available must be a valid date</li>
<li>LibraryCardNumber if available must be numeric.</li>
</ul>

<p>If a book is not borrowed the two last fields are nonexistent.</p>

<p>2 sample rows from 'Books.txt':</p>

<pre><code>9780140455168#2#The Twelve Caesars#Suetonius#Penguin Classics#2007#3#101009#101030#5478
9780141188607#1#Claudius the God#Robert Graves#Penguin Classics#2006#2#080123
</code></pre>

<p>Error lines should be written to 'ErrorLines.txt' with an error-message, e.g. Wrong ISBN. Error-free books should be written to 'NewBooks.txt' sorted by name of author.</p>

<p>Here's what I've got so far. I'm not looking for a complete solution, because I obviously have a looong way to go, but if someone would be so kind as to give me some pointers, I'd be extremely grateful! And yes, it's homework :D</p>

<p>Do I need to make a try loop to validate the input...?</p>

<p>The Library class:</p>

<pre><code>import java.util.ArrayList;
import java.util.*;
import java.io.*;
import java.io.IOException;

public class Library {

public void readFromFile (String filename) throws IOException {

String inLine;
File inFile;

    inFile = new File("Books.txt");
    BufferedReader fIn = new BufferedReader(new FileReader(inFile));

        inLine = fIn.readLine();
        while (inLine != null) {
            inLine = fIn.readLine();
            aBookList.add(inLine + "\n");
        }
        fIn.close();
    }

public void writeToFile (String fileName) throws IOException {

    BufferedWriter bw = null;
        try {
            bw = new BufferedWriter(new FileWriter(fileName));

            bw.write("???"); //Dont know what to put here...
            bw.newLine();
        } catch (IOException e) {
            System.out.println("Error writing file.");
        } finally {
            bw.close();
        }
    }

 public static boolean isISBN13Valid(isbn) {
        int check = 0;
        for (int i = 0; i &lt; 12; i += 2) {
            check += Integer.valueOf(isbn.substring(i, i + 1));
        }
        for (int i = 1; i &lt; 12; i += 2) {
            check += Integer.valueOf(isbn.substring(i, i + 1)) * 3;
        }
        check += Integer.valueOf(isbn.substring(12));
        return check % 10 == 0;
    }
}
</code></pre>

<p>And here's the Book class:</p>

<pre><code>import java.util.*;
import java.io.*;

public class Book {
Book b = new Book();
private static ArrayList&lt;String&gt; aBookList = new ArrayList&lt;String&gt;();

private String Isbn;
private int CopyNumber;
private String Title;
private String Author;
private String Publisher;
private int Year;
private int Statistics;
private String BorrowDate;
private String ReturnDate;
private int LibraryCardNumber;

public void bookInfo (String nIsbn, int nCopyNumber, String nTitle, String nAuthor, String nPublisher, int nYear,
        int nStatistics, String nBorrowDate, String nReturnDate, int nLibraryCardNumber) {

    Isbn = nIsbn; 
    CopyNumber = nCopyNumber; 
    Title = nTitle; 
    Author = nAuthor; 
    Publisher = nPublisher; 
    Year = nYear;
    Statistics = nStatistics; 
    BorrowDate = nBorrowDate; 
    ReturnDate = nReturnDate; 
    LibraryCardNumber = nLibraryCardNumber;
}

public void bookInfo (String Row) {
    StringTokenizer sT = new StringTokenizer(Row);
    Isbn = sT.nextToken("#");
    CopyNumber = Integer.parseInt(sT.nextToken("#") );
    Title = sT.nextToken("#");
    Author = sT.nextToken("#");
    Publisher = sT.nextToken("#");
    Year = Integer.parseInt(sT.nextToken("#") );
    Statistics = Integer.parseInt(sT.nextToken("#") );
    BorrowDate = sT.nextToken("#");
    ReturnDate = sT.nextToken("#");
    LibraryCardNumber = Integer.parseInt(sT.nextToken("#") );
}
public void setIsbn(String nIsbn) {
    Isbn = nIsbn;       
}
public void setCopynumber(int nCopyNumber) {
    CopyNumber = nCopyNumber;       
}
public void setTitle(String nTitle) {
    Title = nTitle;     
}
public void setAuthor(String nAuthor) {
    Author = nAuthor;       
}
public void setPublisher(String nPublisher) {
    Publisher = nPublisher;     
}
public void setYear(int nYear) {
    Year = nYear;       
}
public void setStatistics(int nStatistics) {
    Statistics = nStatistics;       
}
public void setBorrowDate(String nBorrowDate) {
    BorrowDate = nBorrowDate;       
}
public void setReturnDate(String nReturnDate) {
    ReturnDate = nReturnDate;
}
public void setLibraryCardNumber(int nLibraryCardNumber) {
    LibraryCardNumber = nLibraryCardNumber;
}

 public String getAll () {
    String s = " ";
    return (Isbn + s + CopyNumber + s + Title + s + Author + s + Publisher + s +
                   Year + s + Statistics + s + BorrowDate + s + ReturnDate + s +
                   LibraryCardNumber);
}
public void showAll () {
    String t = "\t";
    System.out.println(Isbn + t + CopyNumber + t + Title + t + Author + t +
                       Publisher + t + Year + t + Statistics + t + 
                       BorrowDate + t + ReturnDate + t + LibraryCardNumber);
}
}
</code></pre>

<p>And finally there's the Main class with main method:    </p>

<pre><code>public class Main&lt;aBookList&gt; implements Comparable&lt;aBookList&gt; {
public static void main(String [] args) throws Exception {

    new Library().readFromFile("Books.txt");

    new Library().writeToFile("NewBooks.txt");
    new Library().writeToFile("ErrorLines.txt");

}

@Override
public int compareTo(aBookList o) {
    return 0;
}
}
</code></pre>
