|
|
Re: Help with A project
|
Posted: Dec 8, 2008 11:32 PM
|
|
Homework help again hey?
> Books Management > 1- Insert new books: This command adds a new book to our > library. The added data is stored > in a file. The file is a text file that is comma delimited > in which each entry (book) is found on a > separate line. Each entry must contain the main book > information mentioned before. An > example of one line in the file is as follows: > Core Java, Cay S. Horstmann, Prentice Hall PTR, > 0-13-089468-0, December 01 2000, 5, 3, Programming
Create a class (A Book Object)
public class Book implements Serializable{
private String title;
private String author;
private String publisher;
private String isbn;
private java.util.Date publicationDate;
private String category;
// TODO: create getters and setters - use your IDE
}
// In another class - remember each class should be in a different file
public class Controller {
public static void insert(Book book) {
// Create a file writer to read/write from an existing file
// String line = book.getTitle() + ", " + book.getAuthor() + "...";
// writer.append(line +"\n"); // depending on how your writer is setup
}
public static Book search(String title) {
// Create file reader - you can use the one above if you have extracted it to a method
// List<Book> books = new ArrayList<Book>();
// while (reader.hasMoreLines()){ // this is not real code so don't just copy and paste this you will have to google some of this stuff
// tokenize line create new Book from this line - use StringTokenizer()
}
for (Book book : books) {
if (book.getTitle().equals(title)
return book;
}
return null;
}
// Your delete will use a similar algorithm to the search - now you can just clean your code up, e.g. extract method for reader - or to load all books from a file into an array.
This is as very close to just writing the code for you, hope this helps.
> 2- Search for a book: The system should process a request > by the user to look up information > about a specific entry. The user can supply one or more of > the following; book title (or part of > it), author name, ISBN or category. The system should > provide a list of books that matches the > user request. > 3- Add new copy: The system should prompt the user to > enter book ISBN and the number of > its copies and update the Book entry in the file with the > new number of copies. > 4- Delete book: The user should be prompted for the book > ISBN and that entry should be > deleted from the system (books file). > So if anybody can post the code or just give me some tips > I would be thankful...
|
|