¡¡Hola amigos!!
Este es uno de los primeros proyectos que desarrollé en lenguaje java cuando estaba estudiando. El desarrollo fue individual, luego lo que comparto es la forma en que yo personalmente lo resolví, y hay muchas otras formas de llegar al mismo resultado.

archivos biblioteca eclipse

Sistema de archivos del proyecto Biblioteca en Eclipse

El proyecto lo componen dos clases:

  • La clase Libro.java que contiene tres String con los datos de un ejemplar: Título, Autor e ISBN. Comprueba que el ISBN que introducimos sea correcto, y de no serlo lanza una Excepción.
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package biblioteca;


/**
 *
 * @author Rafathan
 */
public class Libro {


    private String titulo;
    private String autor;
    private String isbn;

    String consulta_autor() {
        return autor;
    }

    void cambia_autor(String autor) {
        this.autor = autor;
    }

    String consulta_titulo() {
        return titulo;
    }

    void cambia_titulo(String titulo) {
        this.titulo = titulo;
    }

    String consulta_isbn() {
        return isbn;
    }

    void cambia_isbn(String isbn) {
        isbn = quitarGuiones (isbn);
        
        if (isbn.length() == 10) {
            if (compruebaIsbn10(isbn) == false) {
                throw new IllegalArgumentException("ISBN no válido");
            }
        } else if (isbn.length() == 13) {
            if (compruebaIsbn13(isbn) == false) {
                throw new IllegalArgumentException("ISBN no válido");
            }
        } else {
            throw new IllegalArgumentException("ISBN no válido");
        }
        this.isbn = isbn;
    }

    private boolean compruebaIsbn10(String isbn) {

        int total = 0;
        int cifra;

        for (int i = 0; i < 10; i++) {
            if (i == 9) {
                if ( (isbn.charAt(i) == 'X')||(isbn.charAt(i) == 'x') ) {
                    cifra = 10;
                } else {
                    cifra = Integer.parseInt(isbn.substring(i, i + 1));
                }
            } else {
                cifra = Integer.parseInt(isbn.substring(i, i + 1));
            }

            total = total + ((i + 1) * cifra);
        }
        if ((total % 11) == 0) {
            return true;
        } else {
            return false;
        }

    }

    private boolean compruebaIsbn13(String isbn) {

        int total = 0;
        int cifra;

        for (int i = 0; i < 12; i++) {
            if ((i % 2) == 0) {
                cifra = Integer.parseInt(isbn.substring(i, i + 1));
            } else {
                cifra = ((Integer.parseInt(isbn.substring(i, i + 1))) * 3);
            }
            total = total + cifra;
        }
        if ((10 - (total % 10)) == (Integer.parseInt(isbn.substring(12)))) {
            return true;
        } else {
            return false;
        }
    }

    private String quitarGuiones(String isbn) {
        isbn = isbn.replaceAll("-", "");
        return isbn;
    }
}
  • La clase Principal.java contiene el Main que ejecuta la aplicación. Podemos introducir los datos del ejemplar, controlar las Excepciones que se produzcan, y posteriormente visualizarlos.
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package biblioteca;

import java.util.Scanner;

/**
 *
 * @author Rafathan
 */
public class Principal {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

     int opcion = 3;
        Scanner reader = new Scanner(System.in);
        boolean error;
        Libro l = new Libro();

        while (opcion != 0) {

            System.out.print("\nMENU\n0-Salir\n1-Nuevo libro.\n2-Ver libro almacenado.\n");
            do {
                try {
                    System.out.print("Seleccion: ");
                    opcion = Integer.parseInt(reader.next());
                    error = false;
                } catch (NumberFormatException a) {
                    System.out.println("Opcion incorrecta.");
                    error = true;
                }
                if ((opcion < 0) || (opcion > 2)) {
                    System.out.println("Opcion incorrecta.");
                    error = true;
                }
            } while (error);
            
            if (opcion == 1) {
                reader.nextLine();
                System.out.print("Titulo del libro: ");
                l.cambia_titulo(reader.nextLine());
                
                System.out.print("Autor del libro: ");
                l.cambia_autor(reader.nextLine());

                do {
                    try {
                        System.out.print("ISBN del libro: ");
                        l.cambia_isbn(reader.nextLine());
                        error = false;
                    } catch (IllegalArgumentException a) {
                        System.out.println("Codigo ISBN no valido.");
                        error = true;
                    }
                } while (error);
            }

            if (opcion == 2) {
                System.out.print("\n\nTitulo: " + l.consulta_titulo() + "\nAutor: " + l.consulta_autor() + "\nCodigo ISBN: " + l.consulta_isbn() + "\n\n");
            }
        }
    }

}
 
salida consola biblioteca

Salida en la consola de Eclipse del proyecto Biblioteca

Podéis ver y descargar estos archivos en mi GitHub

Esta es una aplicación muy sencilla, ya que sólo almacena los datos de un libro. Más adelante, usando arrays, colecciones y base de datos se puede seguir mejorando, y así obtener una auténtica biblioteca con muchos libros.

Hasta pronto.