Hi friends,
I m trying to write a program in Java to manipulate my personal collection of books.
Below is the code I have writen till now. If you have some ideas?

package Books;
import java.util.*;

class Book{
    private int isbn;
    private String title;
    private static int count=0;
    public Book(){
    	count ++;
	public void readBook(){
	int isbn=0;
	Scanner input = new Scanner(System.in);
    String temp;
    	Book book = new Book();	
	    System.out.print("ISBN: ");
	    System.out.print("title: ");
	    String title = input.nextLine();
    public int getCount(){
    	return count;
    public void incrCount(){
    public int getIsbn() {
        return isbn;

    public void setIsbn(int isbn) {
        this.isbn = isbn;

    public String getTitle() {
        return title;

    public void setTitle(String title) {
        this.title = title;
package Books;
import java.util.Scanner;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException, NumberFormatException{
        Scanner input = new Scanner(System.in);
        Book book = new Book();
        int choice;
        Book[] books = new Book[10];
        int currentIndex;
        String temp;
            System.out.println("Library System");
            System.out.println("       1. add book");
            System.out.println("       2. display books");
            System.out.println("       3. save to file");
            System.out.println("       4. load from file");
            System.out.println("       0. exit");
            System.out.print("choice: ");
            temp = input.nextLine();
            choice = Integer.parseInt(temp);
        }while ((choice < 0) || (choice > 4));
        switch (choice){
            case 1: //read isbn, title
                    //add current book to the array
                    books[currentIndex+1] = book;
            case 2: //display array of books
                    System.out.println("ISBN         Title   ");
                    for(int i=0; i< currentIndex; i++){
                    System.out.println(books[i].getIsbn()+"  "+books[i].getTitle()+"  ");
            case 3: break;
            case 4: break;
            case 0: return ;
        }//end while true

Recommended Answers

All 3 Replies

i have some similar code for a cd collection. make 1 class for the collection, and another for the disk (in your cae a book)

your code looks good so far, just try and get all the basic repetitive parts done first. constructors, mutators, acessors

and then work on the more advanced methods

commented: Haven't seen you around in awhile +8

An idea? Use JDBC to store book information then retrieve it later.

Files are ok, but it might be easier to query necessary information than try to make a dozen different methods for obtaining books in certain order, or certain books period.

before I start reading that code ... is there something that doesn't work? and what are you trying to acchieve? my idea of buying a new pair of socks is still an idea I got, but I kinda doubht it'll help your project much further

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.