Java Library

profilehany.b
attachments.zip

library.txt

A:0:Author Name:Street One:Washi:DC:20002:(202)635-0000 B:0:Java One:technica:50.59:0 A:1:Author Name Two:Street Two:New York:NY:12122:(508)123-0000 B:1:Java Two:action:6.14:1

Address.java

Address.java

package   Book ;
//import Book.Address;
//import Library2.Genre;
public   class   Address   {
     String  street ;   // street address
     String  city ;     // city
     String  state ;    // state
     String  zip ;      // zip
     String  phone ;    // phone
     /*
     * Constructor with empty set of arguments - create empty strings
     */
     public   Address (){
        street =   new   String ();
        city   =   new   String ();
        state  =   new   String ();
        zip    =   new   String ();
        phone  =   new   String ();
     }
     /*
     * Constructor with all arguments
     */
     public   Address ( String  s ,   String  c ,   String  z ,   String  st ,   String  p ){
        street  =  s ;
        city    =  c ;
        zip     =  z ;
        state   =  st ;
        phone   =  p ;
     }
    
     /* 
     * setStreet - set street address
     */
     public   void  setStreet  ( String  s ){
        street  =  s ;
     }
     /*
     * getStreet - return street address
     */
     public   String  getStreet (){
         return  street ;
     }
     /* 
     * setCity - set city
     */
     public   void  setCity  ( String  c ){
        city  =  c ;
     }
     /*
     * getCity - return city
     */
     public   String  getCity (){
         return  city ;
     }
     /* 
     * setZip - set zip code
     */
     public   void  setZip  ( String  z ){
        zip  =  z ;
     }
     /*
     * getZip - return zip code
     */
     public   String  getZip (){
         return  zip ;
     }
     /*
     * setState - set state
     */
     public   void  setState ( String  st ){
        state  =  st ;
     }
     /*
     * getState - get state
     */
     public   String  getState (){
         return  state ;
     }
    
     /* 
     * setPhone - set phone number
     */
     public   void  setPhone  ( String  p ){
        phone  =  p ;
     }
     /*
     * getPhone - return phone number
     */
     public   String  getPhone (){
         return  phone ;
     }
     /* Return true if address matches */
     public   boolean  isAddress ( String  s ,   String  c ,   String  z ,   String  st ){
         return   ( s . equalsIgnoreCase ( street )   &&  c . equalsIgnoreCase ( city )   &&
                z . equalsIgnoreCase ( zip )   &&  st . equalsIgnoreCase ( state ));
     }
    
     /*
     * Return address in format street addr:city:zip:phone
     */
     //@Override
     public   String  toString (){
         return  street + ":" + city + ":" + zip + ":" + state + ":" + phone ;
     }
    
}

Author.java

Author.java


package   Book ;

/* 
 * Author class - represents an author 
 * 
 */
public   class   Author   {
     Address  addr ;
     String   name ;   /* Author's name */
     int      index ;    /* index */
    
     /*
     * Constructor with no args
     */
     public   Author (){
        addr  =   new   Address ();
        name  =   new   String ();
        index  =   - 1 ;   /* unspecified */
     }
    
     /* 
     * Constructor with 1 argument - name
     */
     public   Author ( String  n )   {
        name  =  n ;
        addr  =   new   Address ();
        index  =   - 1 ;
     }
    
     /*
     * Constructor with 2 arguments - name and address
     */
     public   Author ( String  n ,   int  ind ,   Address  a ){
        name  =  n ;
        index  =  ind ;
        addr   =  a ;
     }
    
     /* Return true if the author has the same  name */
     public   boolean  isName ( String  n ){
         return  n . equalsIgnoreCase ( name );
     }
     /* Return true if author's index is i */
     public   boolean  isIndex ( int  i ){
         return  getIndex ()   ==  i ;
     }
     /*
     * Return true if string 'n' matches author's name substring
     */
     public   boolean  matchName ( String  n ){
         return  name . matches ( n );
     }
     /*
     * Return true if author's index matches i, same as isAuthorIndex
     */
     public   boolean  matchIndex ( int  i ){
         return  isIndex ( i );
     }
     /*
     * getName - get name
     */
     public   String  getName (){
         return  name ;
     }
     /*
     * setName - set  name
     */
     public   void  setName ( String  n ){
        name  =  n ;
     }
     /*
     * setIndex - set author's index
     */
     public   void  setIndex ( int  ind ){
        index  =  ind ;
     }
     /*
     * getIndex - get author's index
     */
     public   int  getIndex (){
         return  index ;
     }

     /* 
     * getAddress - get address
     */
     public   Address  getAddress (){
         return  addr ;
     }
     /*
     * setAddress - set address
     */
     public   void  setAddress ( Address  a ){
        addr  =  a ;
     }
    
     /*
     * Return author in format first last:street address:city:zip:phone
     */
    @ Override
     public   String  toString (){
         return  name  +   ":"   +  addr ;   // will use addr.toString()
     }
}

Book.java

Book.java

package   Book ;

//This Class represents a book

public   class   Book   {
     Author  author ;
     Title  title ;
     Gendre  gendre ;
     int  index ;  
     float  price ;
    
     /*
     * Constructor with no arguments - initialize members
     */
     public   Book (){
        author  =   new   Author ();
        title   =   new   Title ();
        gendre  =   new   Gendre ();
        price   =   0 ;
        index   =   - 1 ;   /* unspecified */
     }
     /* 
     * Constructor with all arguments
     */
     public   Book ( int  i ,   Title  t ,   Author  a ,   Gendre  g ,   float  p ){
        author  =  a ;
        title  =  t ;
        gendre  =  g ;
        price   =  p ;
        index  =  i ;
     }
    
     /*
     * setPrice - set the book price
     */
     public   void  setPrice ( float  p ){
        price  =  p ;
     }
     /*
     * getPrice - get the book price
     */
     public   float  getPrice (){
         return  price ;
     }
    
     /*
     * setAuthor - set the book's author
     */
     public   void  setAuthor  ( Author  a ){
        author  =  a ;
     }
     /*
     * getAuthor - get author
     */
     public   Author  getAuthor (){
         return  author ;
     }
    
     /*
     * setTitle - set the book title
     */
     public   void  setTitle (   Title  t ){
        title  =  t ;
     }
     /*
     * getTitle - get the book title
     */
     public   Title  getTitle (){
         return  title ;
     }
    
     /*
     * setGendre - set gendre
     */
     public   void  setGendre ( Gendre  g ){
        gendre  =  g ;
     }
     /*
     * getGendre - get gendre
     */
     public   Gendre  getGendre (){
         return  gendre ;
     }
    
     /*
     * setIndex - set index
     */
     public   void  setIndex ( int  ind ){
        index  =  ind ;
     }
     /*
     * getIndex - get index
     */
     public   int  getIndex (){
         return  index ;
     }
    
     /* Book match functions (used for search)
     * isAuthorName - if the author exactly as specified
     * isGendre - if the gendre exactly matches
     * isTitle - if the title exactly matches
     * matchAuthorName - if author matches partially
     * matchTitle - if title matches partially
     * matchGendre - if gendre matches partially
     */
     public   boolean  isAuthorName ( String  a ){
         return  author . isName ( a );
     }
     public   boolean  isGendre ( String  g ){
         return  gendre . isGendre ( g );
     }
     public   boolean  isTitle ( String  t ){
         return  title . isTitle ( t );
     }
     public   boolean  matchAuthorName ( String  a ){
         return  author . matchName ( a );
     }
     public   boolean  matchAuthorIndex ( int  i ){
         return  author . matchIndex ( i );
     }
     public   boolean  matchTitle ( String  t ){
         return  title . matchTitle ( t );
     }
     public   boolean  matchGendre ( String  g ){
         return  gendre . matchGendre ( g );
     }
     /*
     * toString - return in format title:gendre:price
     */
    // @Override
     public   String  toString (){
         return  title  +   ":"   +  gendre  +   ":"   +  price ;
     }
}

Final.java

Final.java

package  demo ;

public   class   Final   extends  javax . swing . JFrame   {

     public   Final ()   {
        initComponents ();
     }

     /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @ SuppressWarnings ( "unchecked" )
     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
     private   void  initComponents ()   {

        firstNameLabel  =   new  javax . swing . JLabel ();
        firstNameField  =   new  javax . swing . JTextField ();
        lastNameLabel  =   new  javax . swing . JLabel ();
        lastNameField  =   new  javax . swing . JTextField ();
        emailLabel  =   new  javax . swing . JLabel ();
        emailField  =   new  javax . swing . JTextField ();
        jScrollPane1  =   new  javax . swing . JScrollPane ();
        availableList  =   new  javax . swing . JList ();
        jScrollPane2  =   new  javax . swing . JScrollPane ();
        selectedList  =   new  javax . swing . JList ();
        cancelButton  =   new  javax . swing . JButton ();
        okButton  =   new  javax . swing . JButton ();
        availableLabel  =   new  javax . swing . JLabel ();
        selectedLabel  =   new  javax . swing . JLabel ();
        jLabel1  =   new  javax . swing . JLabel ();
        jTextField1  =   new  javax . swing . JTextField ();
        jPanel1  =   new  javax . swing . JPanel ();
        unselectAllButton  =   new  javax . swing . JButton ();
        selectAllButton  =   new  javax . swing . JButton ();
        unselectButton  =   new  javax . swing . JButton ();
        selectButton  =   new  javax . swing . JButton ();

        setDefaultCloseOperation ( javax . swing . WindowConstants . EXIT_ON_CLOSE );

        firstNameLabel . setText ( "First Name:" );

        lastNameLabel . setText ( "Last Name:" );

        emailLabel . setText ( "E-mail:" );

        availableList . setModel ( new  javax . swing . AbstractListModel ()   {
             String []  strings  =   {   "Mathematics" ,   "Physics" ,   "Chemistry" ,   "Biology" ,   "Architecture" ,   "Geology"   };
             public   int  getSize ()   {   return  strings . length ;   }
             public   Object  getElementAt ( int  i )   {   return  strings [ i ];   }
         });
        jScrollPane1 . setViewportView ( availableList );

        selectedList . setModel ( new  javax . swing . AbstractListModel ()   {
             String []  strings  =   {   "Philosophy" ,   "Astronomy" ,   "Religion" ,   "Psychology"   };
             public   int  getSize ()   {   return  strings . length ;   }
             public   Object  getElementAt ( int  i )   {   return  strings [ i ];   }
         });
        jScrollPane2 . setViewportView ( selectedList );

        cancelButton . setText ( "Cancel" );

        okButton . setText ( "OK" );

        availableLabel . setText ( "Available Topics:" );

        selectedLabel . setText ( "Selected Topics:" );

        jLabel1 . setText ( "Middle Name:" );

        unselectAllButton . setText ( "<<" );

        selectAllButton . setText ( ">>" );

        unselectButton . setText ( "<" );

        selectButton . setText ( ">" );

        javax . swing . GroupLayout  jPanel1Layout  =   new  javax . swing . GroupLayout ( jPanel1 );
        jPanel1 . setLayout ( jPanel1Layout );
        jPanel1Layout . setHorizontalGroup (
            jPanel1Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
             . addGroup ( jPanel1Layout . createSequentialGroup ()
                 . addGap ( 0 ,   0 ,   0 )
                 . addGroup ( jPanel1Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
                     . addComponent ( selectAllButton )
                     . addComponent ( selectButton )
                     . addComponent ( unselectButton )
                     . addComponent ( unselectAllButton ))
                 . addGap ( 0 ,   0 ,   0 ))
         );

        jPanel1Layout . linkSize ( javax . swing . SwingConstants . HORIZONTAL ,   new  java . awt . Component []   { selectAllButton ,  selectButton ,  unselectAllButton ,  unselectButton });

        jPanel1Layout . setVerticalGroup (
            jPanel1Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
             . addGroup ( jPanel1Layout . createSequentialGroup ()
                 . addContainerGap ( javax . swing . GroupLayout . DEFAULT_SIZE ,   Short . MAX_VALUE )
                 . addComponent ( selectAllButton )
                 . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED )
                 . addComponent ( selectButton )
                 . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED )
                 . addComponent ( unselectButton )
                 . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED )
                 . addComponent ( unselectAllButton )
                 . addContainerGap ( javax . swing . GroupLayout . DEFAULT_SIZE ,   Short . MAX_VALUE ))
         );

        javax . swing . GroupLayout  layout  =   new  javax . swing . GroupLayout ( getContentPane ());
        getContentPane (). setLayout ( layout );
        layout . setHorizontalGroup (
            layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
             . addGroup ( layout . createSequentialGroup ()
                 . addContainerGap ()
                 . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
                     . addGroup ( javax . swing . GroupLayout . Alignment . TRAILING ,  layout . createSequentialGroup ()
                         . addGap ( 0 ,   0 ,   Short . MAX_VALUE )
                         . addComponent ( okButton )
                         . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED )
                         . addComponent ( cancelButton ))
                     . addGroup ( layout . createSequentialGroup ()
                         . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
                             . addGroup ( layout . createSequentialGroup ()
                                 . addComponent ( jScrollPane1 )
                                 . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED )
                                 . addComponent ( jPanel1 ,  javax . swing . GroupLayout . PREFERRED_SIZE ,  javax . swing . GroupLayout . DEFAULT_SIZE ,  javax . swing . GroupLayout . PREFERRED_SIZE )
                                 . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED ))
                             . addComponent ( availableLabel ))
                         . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
                             . addGroup ( layout . createSequentialGroup ()
                                 . addComponent ( selectedLabel )
                                 . addGap ( 0 ,   0 ,   Short . MAX_VALUE ))
                             . addComponent ( jScrollPane2 )))
                     . addGroup ( layout . createSequentialGroup ()
                         . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
                             . addComponent ( firstNameLabel )
                             . addComponent ( lastNameLabel )
                             . addComponent ( emailLabel )
                             . addComponent ( jLabel1 ))
                         . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED )
                         . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
                             . addComponent ( firstNameField )
                             . addComponent ( lastNameField )
                             . addComponent ( emailField )
                             . addComponent ( jTextField1 ))))
                 . addContainerGap ())
         );

        layout . linkSize ( javax . swing . SwingConstants . HORIZONTAL ,   new  java . awt . Component []   { cancelButton ,  okButton });

        layout . setVerticalGroup (
            layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
             . addGroup ( layout . createSequentialGroup ()
                 . addContainerGap ()
                 . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . BASELINE )
                     . addComponent ( firstNameLabel )
                     . addComponent ( firstNameField ,  javax . swing . GroupLayout . PREFERRED_SIZE ,  javax . swing . GroupLayout . DEFAULT_SIZE ,  javax . swing . GroupLayout . PREFERRED_SIZE ))
                 . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED )
                 . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . BASELINE )
                     . addComponent ( jLabel1 )
                     . addComponent ( jTextField1 ,  javax . swing . GroupLayout . PREFERRED_SIZE ,  javax . swing . GroupLayout . DEFAULT_SIZE ,  javax . swing . GroupLayout . PREFERRED_SIZE ))
                 . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED )
                 . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . BASELINE )
                     . addComponent ( lastNameLabel )
                     . addComponent ( lastNameField ,  javax . swing . GroupLayout . PREFERRED_SIZE ,  javax . swing . GroupLayout . DEFAULT_SIZE ,  javax . swing . GroupLayout . PREFERRED_SIZE ))
                 . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED )
                 . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . BASELINE )
                     . addComponent ( emailLabel )
                     . addComponent ( emailField ,  javax . swing . GroupLayout . PREFERRED_SIZE ,  javax . swing . GroupLayout . DEFAULT_SIZE ,  javax . swing . GroupLayout . PREFERRED_SIZE ))
                 . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED )
                 . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . BASELINE )
                     . addComponent ( availableLabel )
                     . addComponent ( selectedLabel ))
                 . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED )
                 . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
                     . addComponent ( jScrollPane1 )
                     . addComponent ( jScrollPane2 )
                     . addComponent ( jPanel1 ,  javax . swing . GroupLayout . DEFAULT_SIZE ,  javax . swing . GroupLayout . DEFAULT_SIZE ,   Short . MAX_VALUE ))
                 . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . UNRELATED )
                 . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . BASELINE )
                     . addComponent ( cancelButton )
                     . addComponent ( okButton ))
                 . addContainerGap ())
         );

        pack ();
     } // </editor-fold>//GEN-END:initComponents

     /**
     *  @param  args the command line arguments
     */
     public   static   void  main ( String  args [])   {
         /* Set the Nimbus look and feel */
         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
         try   {
             for   ( javax . swing . UIManager . LookAndFeelInfo  info  :  javax . swing . UIManager . getInstalledLookAndFeels ())   {
                 if   ( "Nimbus" . equals ( info . getName ()))   {
                    javax . swing . UIManager . setLookAndFeel ( info . getClassName ());
                     break ;
                 }
             }
         }   catch   ( ClassNotFoundException  ex )   {
            java . util . logging . Logger . getLogger ( Final . class . getName ()). log ( java . util . logging . Level . SEVERE ,   null ,  ex );
         }   catch   ( InstantiationException  ex )   {
            java . util . logging . Logger . getLogger ( Final . class . getName ()). log ( java . util . logging . Level . SEVERE ,   null ,  ex );
         }   catch   ( IllegalAccessException  ex )   {
            java . util . logging . Logger . getLogger ( Final . class . getName ()). log ( java . util . logging . Level . SEVERE ,   null ,  ex );
         }   catch   ( javax . swing . UnsupportedLookAndFeelException  ex )   {
            java . util . logging . Logger . getLogger ( Final . class . getName ()). log ( java . util . logging . Level . SEVERE ,   null ,  ex );
         }
         //</editor-fold>

         /* Create and display the form */
        java . awt . EventQueue . invokeLater ( new   Runnable ()   {
            @ Override
             public   void  run ()   {
                 new   Final (). setVisible ( true );
             }
         });
     }
     // Variables declaration - do not modify//GEN-BEGIN:variables
     private  javax . swing . JLabel  availableLabel ;
     private  javax . swing . JList  availableList ;
     private  javax . swing . JButton  cancelButton ;
     private  javax . swing . JTextField  emailField ;
     private  javax . swing . JLabel  emailLabel ;
     private  javax . swing . JTextField  firstNameField ;
     private  javax . swing . JLabel  firstNameLabel ;
     private  javax . swing . JLabel  jLabel1 ;
     private  javax . swing . JPanel  jPanel1 ;
     private  javax . swing . JScrollPane  jScrollPane1 ;
     private  javax . swing . JScrollPane  jScrollPane2 ;
     private  javax . swing . JTextField  jTextField1 ;
     private  javax . swing . JTextField  lastNameField ;
     private  javax . swing . JLabel  lastNameLabel ;
     private  javax . swing . JButton  okButton ;
     private  javax . swing . JButton  selectAllButton ;
     private  javax . swing . JButton  selectButton ;
     private  javax . swing . JLabel  selectedLabel ;
     private  javax . swing . JList  selectedList ;
     private  javax . swing . JButton  unselectAllButton ;
     private  javax . swing . JButton  unselectButton ;
     // End of variables declaration//GEN-END:variables
}

Gendre.java

Gendre.java

package   Book ;

import  java . util . ArrayList ;

/* 
 * This class represents one 
 * or more (not yet implemented)
 * book gendre (s) 
 */
public   class   Gendre   {
     ArrayList < String >  list ;
     /*
     * Constructor - create empty set of gendres
     */
     public   Gendre ()   {
        list  =   new   ArrayList < String > ();   // create new list
     }
     /* 
     * Constructor with 1 argument - gendre
     */
     public   Gendre ( String  g )   {
        list  =   new   ArrayList < String > ();   // create new list
        list . add ( g );
     }
     /* 
     * setGendre() - set gendre
     * 
     */
     public   void  setGendre ( ArrayList  gendre ){
            list  =  gendre ;
     }
     /* 
     * getGendre() - get a list of gendres of this book 
     */
     public   ArrayList < String >  getGendre (){
         return  list ;
     }
    
     /* 
     * 
     * isGendre - return true if this gendre is already in a list of gendres 
     */
     public   boolean  isGendre ( String  gendre )   {
         for   ( int  i = 0 ;  i < list . size ();  i ++ )   {
             if   ( list . get ( i ). equalsIgnoreCase ( gendre ))   return   true ;
         }
         return   false ;
     }
    
     /* 
     * matchGendre - return true if 'n' matches any gendre substring
     */
     public   boolean  matchGendre ( String  g ){
         for   ( int  i = 0 ;  i < list . size ();  i ++ ){
             if   ( list . get ( i ). matches ( g ))   return   true ;
         }
         return   false ;
     }
    
     /* convert list of gendres to gendre1,gendre2,gendre3,.. string */
    @ Override
     public   String  toString (){
         String  result = new   String ();
         if   ( list . size () > 0 )  result  =  list . get ( 0 );
         for   ( int  i  =   1 ;  i < list . size ();  i ++ )   {
            result = result + "," + list . get ( i );
         }
         return  result ;
     }
}

LibrartyUI.java

LibrartyUI.java



/*
 * Use separate package for GUI
 * import our 'books' classes
 */

import  java . io . * ;

public   class   LibrartyUI   extends  javax . swing . JFrame   {
     static   Library  lib ;
  
     /**
     * Creates new form BookStoreUI
     */
     public   LibrartyUI ()   {
         super ();
        initComponents ();
     }

     /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @ SuppressWarnings ( "unchecked" )
     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
     private   void  initComponents ()   {

        jMenuBar1  =   new  javax . swing . JMenuBar ();
        jMenu1  =   new  javax . swing . JMenu ();
        jMenu2  =   new  javax . swing . JMenu ();
        buttonGroup1  =   new  javax . swing . ButtonGroup ();
        buttonGroup2  =   new  javax . swing . ButtonGroup ();
        jPanel1  =   new  javax . swing . JPanel ();
        jLabel1  =   new  javax . swing . JLabel ();
        jRadioButtonAuthorIndex  =   new  javax . swing . JRadioButton ();
        jRadioButtonBookIndex  =   new  javax . swing . JRadioButton ();
        jRadioButtonBookTitle  =   new  javax . swing . JRadioButton ();
        jRadioButtonGendre  =   new  javax . swing . JRadioButton ();
        jLabel2  =   new  javax . swing . JLabel ();
        jTextFieldSearch  =   new  javax . swing . JTextField ();
        jButtonSearch  =   new  javax . swing . JButton ();
        jLabel3  =   new  javax . swing . JLabel ();
        jScrollPane1  =   new  javax . swing . JScrollPane ();
        jTextArea1  =   new  javax . swing . JTextArea ();
        jMenuBar2  =   new  javax . swing . JMenuBar ();
        jMenu3  =   new  javax . swing . JMenu ();
        jMenuItem1  =   new  javax . swing . JMenuItem ();

        jMenu1 . setText ( "File" );
        jMenuBar1 . add ( jMenu1 );

        jMenu2 . setText ( "Edit" );
        jMenuBar1 . add ( jMenu2 );

        setDefaultCloseOperation ( javax . swing . WindowConstants . EXIT_ON_CLOSE );

        jLabel1 . setText ( "Search on:" );

        buttonGroup1 . add ( jRadioButtonAuthorIndex );
        jRadioButtonAuthorIndex . setSelected ( true );
        jRadioButtonAuthorIndex . setText ( "Author Index" );
        jRadioButtonAuthorIndex . addActionListener ( new  java . awt . event . ActionListener ()   {
             public   void  actionPerformed ( java . awt . event . ActionEvent  evt )   {
                jRadioButtonAuthorIndexActionPerformed ( evt );
             }
         });

        buttonGroup1 . add ( jRadioButtonBookIndex );
        jRadioButtonBookIndex . setText ( "Book Index" );
        jRadioButtonBookIndex . addActionListener ( new  java . awt . event . ActionListener ()   {
             public   void  actionPerformed ( java . awt . event . ActionEvent  evt )   {
                jRadioButtonBookIndexActionPerformed ( evt );
             }
         });

        buttonGroup1 . add ( jRadioButtonBookTitle );
        jRadioButtonBookTitle . setText ( "Book Title" );
        jRadioButtonBookTitle . addActionListener ( new  java . awt . event . ActionListener ()   {
             public   void  actionPerformed ( java . awt . event . ActionEvent  evt )   {
                jRadioButtonBookTitleActionPerformed ( evt );
             }
         });

        buttonGroup1 . add ( jRadioButtonGendre );
        jRadioButtonGendre . setText ( "Gendre" );

        jLabel2 . setText ( "Search for:" );

        jButtonSearch . setText ( "Search " );
        jButtonSearch . addActionListener ( new  java . awt . event . ActionListener ()   {
             public   void  actionPerformed ( java . awt . event . ActionEvent  evt )   {
                jButtonSearchActionPerformed ( evt );
             }
         });

        javax . swing . GroupLayout  jPanel1Layout  =   new  javax . swing . GroupLayout ( jPanel1 );
        jPanel1 . setLayout ( jPanel1Layout );
        jPanel1Layout . setHorizontalGroup (
            jPanel1Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
             . addGroup ( jPanel1Layout . createSequentialGroup ()
                 . addGroup ( jPanel1Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
                     . addGroup ( jPanel1Layout . createSequentialGroup ()
                         . addGap ( 10 ,   10 ,   10 )
                         . addComponent ( jLabel1 ))
                     . addGroup ( jPanel1Layout . createSequentialGroup ()
                         . addContainerGap ()
                         . addGroup ( jPanel1Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
                             . addComponent ( jRadioButtonGendre )
                             . addComponent ( jRadioButtonBookTitle )
                             . addComponent ( jRadioButtonBookIndex )
                             . addComponent ( jRadioButtonAuthorIndex ))))
                 . addGap ( 36 ,   36 ,   36 )
                 . addGroup ( jPanel1Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
                     . addComponent ( jLabel2 )
                     . addComponent ( jTextFieldSearch ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   246 ,  javax . swing . GroupLayout . PREFERRED_SIZE )
                     . addComponent ( jButtonSearch ))
                 . addContainerGap ( 809 ,   Short . MAX_VALUE ))
         );
        jPanel1Layout . setVerticalGroup (
            jPanel1Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
             . addGroup ( jPanel1Layout . createSequentialGroup ()
                 . addGroup ( jPanel1Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . BASELINE )
                     . addComponent ( jLabel1 )
                     . addComponent ( jLabel2 ))
                 . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED )
                 . addGroup ( jPanel1Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . BASELINE )
                     . addComponent ( jRadioButtonAuthorIndex ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   23 ,  javax . swing . GroupLayout . PREFERRED_SIZE )
                     . addComponent ( jTextFieldSearch ,  javax . swing . GroupLayout . PREFERRED_SIZE ,  javax . swing . GroupLayout . DEFAULT_SIZE ,  javax . swing . GroupLayout . PREFERRED_SIZE ))
                 . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED )
                 . addGroup ( jPanel1Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
                     . addGroup ( jPanel1Layout . createSequentialGroup ()
                         . addComponent ( jRadioButtonBookIndex ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   23 ,  javax . swing . GroupLayout . PREFERRED_SIZE )
                         . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED )
                         . addComponent ( jRadioButtonBookTitle ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   23 ,  javax . swing . GroupLayout . PREFERRED_SIZE ))
                     . addComponent ( jButtonSearch ))
                 . addGap ( 2 ,   2 ,   2 )
                 . addComponent ( jRadioButtonGendre ))
         );

        jLabel3 . setText ( "Search result:" );

        jTextArea1 . setColumns ( 20 );
        jTextArea1 . setRows ( 5 );
        jScrollPane1 . setViewportView ( jTextArea1 );

        jMenu3 . setText ( "File" );

        jMenuItem1 . setText ( "Exit" );
        jMenuItem1 . addActionListener ( new  java . awt . event . ActionListener ()   {
             public   void  actionPerformed ( java . awt . event . ActionEvent  evt )   {
                jMenuItem1ActionPerformed ( evt );
             }
         });
        jMenu3 . add ( jMenuItem1 );

        jMenuBar2 . add ( jMenu3 );

        setJMenuBar ( jMenuBar2 );

        javax . swing . GroupLayout  layout  =   new  javax . swing . GroupLayout ( getContentPane ());
        getContentPane (). setLayout ( layout );
        layout . setHorizontalGroup (
            layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
             . addGroup ( layout . createSequentialGroup ()
                 . addContainerGap ()
                 . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
                     . addGroup ( layout . createSequentialGroup ()
                         . addComponent ( jPanel1 ,  javax . swing . GroupLayout . DEFAULT_SIZE ,  javax . swing . GroupLayout . DEFAULT_SIZE ,   Short . MAX_VALUE )
                         . addContainerGap ())
                     . addGroup ( layout . createSequentialGroup ()
                         . addGap ( 10 ,   10 ,   10 )
                         . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
                             . addComponent ( jLabel3 )
                             . addComponent ( jScrollPane1 ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   634 ,  javax . swing . GroupLayout . PREFERRED_SIZE ))
                         . addGap ( 552 ,   552 ,   552 ))))
         );
        layout . setVerticalGroup (
            layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
             . addGroup ( layout . createSequentialGroup ()
                 . addContainerGap ()
                 . addComponent ( jPanel1 ,  javax . swing . GroupLayout . PREFERRED_SIZE ,  javax . swing . GroupLayout . DEFAULT_SIZE ,  javax . swing . GroupLayout . PREFERRED_SIZE )
                 . addGap ( 23 ,   23 ,   23 )
                 . addComponent ( jLabel3 )
                 . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED )
                 . addComponent ( jScrollPane1 ,  javax . swing . GroupLayout . DEFAULT_SIZE ,   159 ,   Short . MAX_VALUE )
                 . addContainerGap ())
         );

        pack ();
     } // </editor-fold>//GEN-END:initComponents

     private   void  jMenuItem1ActionPerformed ( java . awt . event . ActionEvent  evt )   { //GEN-FIRST:event_jMenuItem1ActionPerformed
         // TODO add your handling code here:
         System . exit ( 0 );
     } //GEN-LAST:event_jMenuItem1ActionPerformed

     private   void  jRadioButtonBookTitleActionPerformed ( java . awt . event . ActionEvent  evt )   { //GEN-FIRST:event_jRadioButtonBookTitleActionPerformed
         // TODO add your handling code here:
     } //GEN-LAST:event_jRadioButtonBookTitleActionPerformed

     private   void  jRadioButtonAuthorIndexActionPerformed ( java . awt . event . ActionEvent  evt )   { //GEN-FIRST:event_jRadioButtonAuthorIndexActionPerformed
         // TODO add your handling code here:
     } //GEN-LAST:event_jRadioButtonAuthorIndexActionPerformed

     private   void  jButtonSearchActionPerformed ( java . awt . event . ActionEvent  evt )   { //GEN-FIRST:event_jButtonSearchActionPerformed
         // TODO add your handling code here
       
     
         String  strAuthorame =   "" ;
         if   ( jRadioButtonAuthorIndex . isSelected ()){
             // Search by Author Index
             int  index ;
            index  =   Integer . parseInt ( jTextFieldSearch . getText ());
             if   ( lib . searchOnAuthorIndex ( index ))   {
                 // Update Author's information
                 Author  author  =  lib . getAuthorOnIndex ( index );
                jTextArea1 . setText ( author . toString ());
             }
             else   {   // author not found - setup empty fields
                  strAuthorame  =   "*** NOT FOUND ***" ;

             jTextArea1 . setText ( strAuthorame );
             }
             /* After searching on Author Index we also setup currentBook Index */
             if   ( lib . getCurrentBookIndex ()   !=   - 1 )   {
                 Book  book ;
                book  =  lib . getBookOnIndex ( lib . getCurrentBookIndex ());

              jTextArea1 . setText ( book . toString ());
             }
             else   {   // no more books not found with this author
            strAuthorame =   "" ;
          jTextArea1 . setText ( "*** NOT FOUND ***" );
             }
         }
         /* Search by Book Index */
         else   if   ( jRadioButtonBookIndex . isSelected ())   {
             // Search by Author Index
             int  index ;
            index  =   Integer . parseInt ( jTextFieldSearch . getText ());
             if   ( lib . searchOnBookIndex ( index ))   {
                 // Update Book information
                 Book  book  =  lib . getBookOnIndex ( index );
                 String  bk  =  book . toString () + "\n" ;

                 Author  author  =  lib . getAuthorOnIndex ( lib . getCurrentAuthorIndex ());
              bk  +=  author . toString ();
               jTextArea1 . setText ( bk );
             }
             else   {   // Book not found
                   String  strTitle  = ( "*** NOT FOUND ***" );

          jTextArea1 . setText ( strTitle );
             }
         }
         /*
         * Search by BOOK TITLE 
         */
         else   if   ( jRadioButtonBookTitle . isSelected ()){
             String  title  =  jTextFieldSearch . getText ();
             /* If book found */
             if   ( lib . searchOnBookTitle ( title )){
                 int  index  =  lib . getCurrentBookIndex ();
                 // Update Book information
                 Book  book  =  lib . getBookOnIndex ( index );
                String  strTitle  = ( book . getTitle (). toString ()) + "\n" ;
               strTitle  +=   ( book . getGendre (). toString ()) + "\n" ;
                 Author  author  =  lib . getAuthorOnIndex ( lib . getCurrentAuthorIndex ());
                strTitle  +=  author . toString () + "\n" ;
                 Address  address  =  author . getAddress ();
                strTitle  +=  address . toString ();
                jTextArea1 . setText ( strTitle );
             }
             else   {   // Book not found (no more books found)
                 String  strTitle  = ( "*** NOT FOUND ***" );
                    jTextArea1 . setText ( strTitle );
             }
         }
         /*
         * Search by BOOK GENDRE
         */
         else   if   ( jRadioButtonGendre . isSelected ()){
             String  gendre  =  jTextFieldSearch . getText ();
             /* If book found */
             if   ( lib . searchOnBookGendre ( gendre )){
                 int  index  =  lib . getCurrentBookIndex ();
                 // Update Book information
                 Book  book  =  lib . getBookOnIndex ( index );
                 String   strTitle  = ( book . toString ())   +   "\n" ;

                 Author  author  =  lib . getAuthorOnIndex ( lib . getCurrentAuthorIndex ());
                  strTitle  += ( author . toString ())   +   "\n" ;

                 Address  address  =  author . getAddress ();
                strTitle  += ( address . toString ())   +   "\n" ;
               strTitle  += ( book . getGendre (). toString ())   +   "\n" ;

              jTextArea1 . setText ( strTitle );

             }
             else   {   // Book not found (no more books found)
                   String  strTitle  = ( "*** NOT FOUND ***" );
                    jTextArea1 . setText ( strTitle );
             }
         }

        
     } //GEN-LAST:event_jButtonSearchActionPerformed

     private   void  jRadioButtonBookIndexActionPerformed ( java . awt . event . ActionEvent  evt )   { //GEN-FIRST:event_jRadioButtonBookIndexActionPerformed
         // TODO add your handling code here:
} //GEN-LAST:event_jRadioButtonBookIndexActionPerformed

     /*
     * Reset search results
     */
     /**
     *  @param  args the command line arguments
     */
     public   static   void  main ( String  args [])   throws   IOException   {
         /*
         * Read library file
         */
        lib  =   new   Library ();   // use constructor without filename
        lib . readLibrary ();   // try to read and parse data file
        
         /*
         * Set the Nimbus look and feel
         */
         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
         /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
         try   {
             for   ( javax . swing . UIManager . LookAndFeelInfo  info  :  javax . swing . UIManager . getInstalledLookAndFeels ())   {
                 if   ( "Nimbus" . equals ( info . getName ()))   {
                    javax . swing . UIManager . setLookAndFeel ( info . getClassName ());
                     break ;
                 }
             }
         }   catch   ( ClassNotFoundException  ex )   {
            java . util . logging . Logger . getLogger ( LibrartyUI . class . getName ()). log ( java . util . logging . Level . SEVERE ,   null ,  ex );
         }   catch   ( InstantiationException  ex )   {
            java . util . logging . Logger . getLogger ( LibrartyUI . class . getName ()). log ( java . util . logging . Level . SEVERE ,   null ,  ex );
         }   catch   ( IllegalAccessException  ex )   {
            java . util . logging . Logger . getLogger ( LibrartyUI . class . getName ()). log ( java . util . logging . Level . SEVERE ,   null ,  ex );
         }   catch   ( javax . swing . UnsupportedLookAndFeelException  ex )   {
            java . util . logging . Logger . getLogger ( LibrartyUI . class . getName ()). log ( java . util . logging . Level . SEVERE ,   null ,  ex );
         }
         //</editor-fold>

         /*
         * Create and display the form
         */
        java . awt . EventQueue . invokeLater ( new   Runnable ()   {

             public   void  run ()   {
                 new   LibrartyUI (). setVisible ( true );
             }
         });
     }
     // Variables declaration - do not modify//GEN-BEGIN:variables
     private  javax . swing . ButtonGroup  buttonGroup1 ;
     private  javax . swing . ButtonGroup  buttonGroup2 ;
     private  javax . swing . JButton  jButtonSearch ;
     private  javax . swing . JLabel  jLabel1 ;
     private  javax . swing . JLabel  jLabel2 ;
     private  javax . swing . JLabel  jLabel3 ;
     private  javax . swing . JMenu  jMenu1 ;
     private  javax . swing . JMenu  jMenu2 ;
     private  javax . swing . JMenu  jMenu3 ;
     private  javax . swing . JMenuBar  jMenuBar1 ;
     private  javax . swing . JMenuBar  jMenuBar2 ;
     private  javax . swing . JMenuItem  jMenuItem1 ;
     private  javax . swing . JPanel  jPanel1 ;
     private  javax . swing . JRadioButton  jRadioButtonAuthorIndex ;
     private  javax . swing . JRadioButton  jRadioButtonBookIndex ;
     private  javax . swing . JRadioButton  jRadioButtonBookTitle ;
     private  javax . swing . JRadioButton  jRadioButtonGendre ;
     private  javax . swing . JScrollPane  jScrollPane1 ;
     private  javax . swing . JTextArea  jTextArea1 ;
     private  javax . swing . JTextField  jTextFieldSearch ;
     // End of variables declaration//GEN-END:variables

}

Library.java

Library.java

package   Book ;

import  java . io . * ;
import  java . util . ArrayList ;
import  java . util . HashMap ;
import  java . util . Map ;

//Library class represents a library of the books 
public   class   Library   {
     String  datafile ;  
     ArrayList   < Author >  authors ;
     Map  authorsMap ;
     ArrayList   < Book >  books ;
     Map  booksMap ;
     int  currentAuthor ;
     int  currentBook ;
     int  lastSearchType ;  
     boolean  exactSearch ;
    
     //Constructor with no arguments    
     public   Library (){
        datafile  =   "C:\\Documents and Settings\\brenda_handy\\My Documents\\NetBeansProjects\\Form2\\src\\Book\\library.txt" ;
        lastSearchType  =   0 ;
        currentBook  =   - 1 ;
        currentAuthor  =   - 1 ;
        exactSearch  =   true ;
        authors  =   new   ArrayList   <>   ();
        books    =   new   ArrayList   <>   ();
        booksMap  =   new   HashMap ();
        authorsMap  =   new   HashMap ();
     }
     //Creating constructor with argument 
         public   Library ( String  filename ){
        datafile  =  filename ;
        lastSearchType  =   0 ;
        currentBook  =   - 1 ;
        currentAuthor  =   - 1 ;
        exactSearch  =   true ;
        authors  =   new   ArrayList   <>   ();
        books    =   new   ArrayList   <>   ();
         booksMap  =   new   HashMap ();
        authorsMap  =   new   HashMap ();
     }
     //readLibrary method
     public   boolean  readLibrary ()   throws   IOException    {
        
         File  f  =   new   File ( datafile );
         try   ( BufferedReader  in  =   new   BufferedReader ( new   FileReader ( f )))   {
             String  buffer ;
            
    
             while   ( in . ready ()){
                buffer  =  in . readLine ();
                 if   ( buffer . equals ( "" )){
                     break ;   // parse Book
                 }
                 else   {
                     // Split the string on ':'
                     String  str [];                 
                    str  =  buffer . split ( ":" );
                     switch   ( str [ 0 ]. charAt ( 0 ))   {
                     case   'A' :   // parse Author
                         Author  author = new   Author ();
                        author . setName ( str [ 2 ]);
                        author . setIndex ( Integer . parseInt ( str [ 1 ]));
                         // parse Address
                         Address  address = new   Address ();
                        address . setStreet ( str [ 3 ]);
                        address . setCity ( str [ 4 ]);
                        address . setState ( str [ 5 ]);
                        address . setZip ( str [ 6 ]);
                        address . setPhone ( str [ 7 ]);
                         // Assign address to the Author
                        author . setAddress ( address );
                         // Add author to the global author's list
                        authors . add ( author );
                          // Add author to the global author's map using index
                        authorsMap . put ( str [ 1 ],  author );
                         break ;
                     case   'B' :
                         Book  book      =   new   Book ();
                         Title  title    =   new   Title ( str [ 2 ]);
                        book . setTitle ( title );
                         Gendre  gendre  =   new   Gendre ( str [ 3 ]);
                        book . setGendre ( gendre );
                         // Locate author by index and link to this book
    
                        book . setAuthor ( authors . get ( Integer . parseInt ( str [ 5 ])));
                        book . setIndex ( Integer . parseInt ( str [ 1 ]));
                        book . setPrice ( Float . parseFloat ( str [ 4 ]));
                         // Add the book to global book's list
                        books . add ( book );
                          // Add book to the global author's map using index
                        booksMap . put ( str [ 1 ],  book );
                         break ;  
                     }
                 }
             }
         }
         return   true ;
     }
    
     /*
     * writeLibrary - write all data to datafile
     *          return  true on success
     *                  false on error
     */
     public   boolean  writeLibrary ()   throws   IOException   {
         FileOutputStream  fos  =   new   FileOutputStream ( datafile );
         Writer  out  =   new   OutputStreamWriter ( fos ,   "UTF-8" );
         String  buffer ;
         Author  author ;
         Book  book ;
        
         /* 
         * Write authors, then books
         */
         for   ( int  i = 0 ;  i < authors . size ();  i ++ )   {
            author  =  authors . get ( i );
            buffer = "A:"   +  author . getIndex ()   +   ":"   +  author  +   "\n" ;   // .toString() is here
            out . write ( buffer );
         }
         /*
         * Write books
         */
         for   ( int  i = 0 ;  i < books . size ();  i ++ )   {
            book  =  books . get ( i );
            buffer  =   "B:"   +  book . getIndex ()   +   ":"   +  book  +   "\n" ;   // .toString is auto
            out . write ( buffer );
         }
         // close output stream and file
        out . close ();
        fos . close ();
         return   true ;
     }
    
     /*
     * setSearchType - set type of the next search
     */
     public   void  setSearchType ( int  type ){
        lastSearchType  =  type ;
     }
     /*
     * getSearchType - get type of the last search
     */
     public   int  getSearchType (){
         return  lastSearchType ;
     }
    
     /* 
     * searchOnAuthorIndex - search author on index,
     *   return true if found
     *   set 'currentAuthor' to ind
     *   set 'currentBook' to first book of this author or -1 if not found
     */
     public   boolean  searchOnAuthorIndex ( int  ind )   {         
         if   ( authors  ==   null   ||  authors . size () <= ind  ||  ind < 0 )   return   false ;
         /*
         * Now decide if we 'continue' search just starting a new one
         */
         if   ( currentAuthor  ==  ind  &&  currentBook >= 0 )   {
            currentBook ++ ;
         }  
         else   {
            currentBook = 0 ;
         }
        
        currentAuthor = ind ;
        
         for   (;  currentBook < books . size ();  currentBook ++ ){
             if   ( books . get ( currentBook ). getAuthor (). getIndex ()   ==  ind )   {
                 return   true ;   // author found and book found
             }
         }
        currentBook  =   - 1 ;
         return   true ;   // book not found, but author found
     }
    
     /* 
     * searchOnBookIndex - search book on index,
     *   return true if found
     *   set 'currentBook' to ind of the book found
     *   set 'currentAuthor' to the book's author
     */
     public   boolean  searchOnBookIndex ( int  ind )   {         
         if   ( books  ==   null   ||  books . size () <= ind  ||  ind < 0 )   return   false ;
        currentBook = ind ;
        currentAuthor  =  books . get ( ind ). getAuthor (). getIndex ();
         return   true ;
     }

     /*
     * getAuthorOnIndex - return author by index
     * ind should be valid
     */
     public   Author  getAuthorOnIndex ( int  ind ){
         return   ( Author ) authorsMap . get ( ind + "" );
     }
    
     /* 
     * getCurrentBookIndex - return current book index
     */
     public   int  getCurrentBookIndex (){
         return  currentBook ;
     }
    
    
     /* 
     * searchOnBookTitle - search on book title
     * title - title to search
     * exactMatch - should we compare the title exactly or not
     * return true if book found
     * on success, setup currentBook and currentAuthor
     * on failure - both set to -1
     */
     public   boolean  searchOnBookTitle ( String  title ){
         if   ( currentBook >= 0 ){
            currentBook ++ ;
         }
         else   {
            currentBook = 0 ;
         }
         for   ( currentBook = 0 ; currentBook < books . size (); currentBook ++ ){
                 if   ( books . get ( currentBook ). isTitle ( title ))   {
                     break ;    /* found */
                 }
             else   {
                 if   ( books . get ( currentBook ). matchTitle ( title ))   {
                     break ;   /* found */
                 }
             }
         }
         /* Not found */
         if   ( currentBook >= books . size ())   {
            currentBook =- 1 ;
             return   false ;
         }
         /* Now find the author */
        currentAuthor  =  books . get ( currentBook ). getAuthor (). getIndex ();
         return   true ;
     }
     /* 
     * searchOnBookGendre - search on book gendre
     * gendre - gendre to search
     * exactMatch - should we compare the gendre exactly or not
     * return true if book found
     * on success, setup currentBook and currentAuthor
     * on failure - both set to -1
     */
     public   boolean  searchOnBookGendre ( String  gendre ){
         if   ( currentBook >= 0 ){
            currentBook ++ ;
         }
         else   {
            currentBook = 0 ;
         }
         for   ( currentBook = 0 ; currentBook < books . size (); currentBook ++ ){
                 if   ( books . get ( currentBook ). isGendre ( gendre ))   {
                     break ;    /* found */
                 }
             else   {
                 if   ( books . get ( currentBook ). matchGendre ( gendre ))   {
                     break ;   /* found */
                 }
             }
         }
         /* Not found */
         if   ( currentBook >= books . size ())   {
            currentBook =- 1 ;
             return   false ;
         }
         /* Now find the author */
        currentAuthor  =  books . get ( currentBook ). getAuthor (). getIndex ();
         return   true ;
     }
    
     /*
     * Search from the beginning
     */
     public   void  searchReset ()   {
        currentBook  =   - 1 ;
        currentAuthor  =   - 1 ;
     }
     /* 
     * getCurrentAuthorIndex - return current author index
     */
     public   int  getCurrentAuthorIndex (){
         return  currentAuthor ;
     }

     //Returns book on index
      public   Book  getBookOnIndex ( int  ind ){
        return   ( Book ) booksMap . get ( ind + "" );
     }
}

LibraryUI.java

LibraryUI.java



/*
 * Use separate package for GUI
 * import our 'books' classes
 */
package   Book ;
import  java . io . IOException ;

public   class   LibraryUI   extends  javax . swing . JFrame   {
     static   Library  lib ;
 
     // Creates new form BookStoreUI
     
     public   LibraryUI ()   {
        initComponents ();
     }

     /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @ SuppressWarnings ( "unchecked" )
     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
     private   void  initComponents ()   {

        jMenuBar1  =   new  javax . swing . JMenuBar ();
        jMenu1  =   new  javax . swing . JMenu ();
        jMenu2  =   new  javax . swing . JMenu ();
        buttonGroup1  =   new  javax . swing . ButtonGroup ();
        buttonGroup2  =   new  javax . swing . ButtonGroup ();
        jPanel1  =   new  javax . swing . JPanel ();
        jLabel1  =   new  javax . swing . JLabel ();
        jRadioButtonAuthorIndex  =   new  javax . swing . JRadioButton ();
        jRadioButtonBookIndex  =   new  javax . swing . JRadioButton ();
        jRadioButtonBookTitle  =   new  javax . swing . JRadioButton ();
        jRadioButtonGendre  =   new  javax . swing . JRadioButton ();
        jLabel2  =   new  javax . swing . JLabel ();
        jTextFieldSearch  =   new  javax . swing . JTextField ();
        jButtonSearch  =   new  javax . swing . JButton ();
        jLabel3  =   new  javax . swing . JLabel ();
        jScrollPane1  =   new  javax . swing . JScrollPane ();
        jTextArea1  =   new  javax . swing . JTextArea ();
        jMenuBar2  =   new  javax . swing . JMenuBar ();
        jMenu3  =   new  javax . swing . JMenu ();
        jMenuItem1  =   new  javax . swing . JMenuItem ();

        jMenu1 . setText ( "File" );
        jMenuBar1 . add ( jMenu1 );

        jMenu2 . setText ( "Edit" );
        jMenuBar1 . add ( jMenu2 );

        setDefaultCloseOperation ( javax . swing . WindowConstants . EXIT_ON_CLOSE );

        jLabel1 . setText ( "Search on:" );

        buttonGroup1 . add ( jRadioButtonAuthorIndex );
        jRadioButtonAuthorIndex . setSelected ( true );
        jRadioButtonAuthorIndex . setText ( "Author Index" );
        jRadioButtonAuthorIndex . addActionListener ( new  java . awt . event . ActionListener ()   {
             public   void  actionPerformed ( java . awt . event . ActionEvent  evt )   {
                jRadioButtonAuthorIndexActionPerformed ( evt );
             }
         });

        buttonGroup1 . add ( jRadioButtonBookIndex );
        jRadioButtonBookIndex . setText ( "Book Index" );
        jRadioButtonBookIndex . addActionListener ( new  java . awt . event . ActionListener ()   {
             public   void  actionPerformed ( java . awt . event . ActionEvent  evt )   {
                jRadioButtonBookIndexActionPerformed ( evt );
             }
         });

        buttonGroup1 . add ( jRadioButtonBookTitle );
        jRadioButtonBookTitle . setText ( "Book Title" );
        jRadioButtonBookTitle . addActionListener ( new  java . awt . event . ActionListener ()   {
             public   void  actionPerformed ( java . awt . event . ActionEvent  evt )   {
                jRadioButtonBookTitleActionPerformed ( evt );
             }
         });

        buttonGroup1 . add ( jRadioButtonGendre );
        jRadioButtonGendre . setText ( "Gendre" );

        jLabel2 . setText ( "Search for:" );

        jButtonSearch . setText ( "Search " );
        jButtonSearch . addActionListener ( new  java . awt . event . ActionListener ()   {
             public   void  actionPerformed ( java . awt . event . ActionEvent  evt )   {
                jButtonSearchActionPerformed ( evt );
             }
         });

        javax . swing . GroupLayout  jPanel1Layout  =   new  javax . swing . GroupLayout ( jPanel1 );
        jPanel1 . setLayout ( jPanel1Layout );
        jPanel1Layout . setHorizontalGroup (
            jPanel1Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
             . addGroup ( jPanel1Layout . createSequentialGroup ()
                 . addGroup ( jPanel1Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
                     . addGroup ( jPanel1Layout . createSequentialGroup ()
                         . addGap ( 10 ,   10 ,   10 )
                         . addComponent ( jLabel1 ))
                     . addGroup ( jPanel1Layout . createSequentialGroup ()
                         . addContainerGap ()
                         . addGroup ( jPanel1Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
                             . addComponent ( jRadioButtonGendre )
                             . addComponent ( jRadioButtonBookTitle )
                             . addComponent ( jRadioButtonBookIndex )
                             . addComponent ( jRadioButtonAuthorIndex ))))
                 . addGap ( 36 ,   36 ,   36 )
                 . addGroup ( jPanel1Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
                     . addComponent ( jLabel2 )
                     . addComponent ( jTextFieldSearch ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   246 ,  javax . swing . GroupLayout . PREFERRED_SIZE )
                     . addComponent ( jButtonSearch ))
                 . addContainerGap ( 809 ,   Short . MAX_VALUE ))
         );
        jPanel1Layout . setVerticalGroup (
            jPanel1Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
             . addGroup ( jPanel1Layout . createSequentialGroup ()
                 . addGroup ( jPanel1Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . BASELINE )
                     . addComponent ( jLabel1 )
                     . addComponent ( jLabel2 ))
                 . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED )
                 . addGroup ( jPanel1Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . BASELINE )
                     . addComponent ( jRadioButtonAuthorIndex ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   23 ,  javax . swing . GroupLayout . PREFERRED_SIZE )
                     . addComponent ( jTextFieldSearch ,  javax . swing . GroupLayout . PREFERRED_SIZE ,  javax . swing . GroupLayout . DEFAULT_SIZE ,  javax . swing . GroupLayout . PREFERRED_SIZE ))
                 . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED )
                 . addGroup ( jPanel1Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
                     . addGroup ( jPanel1Layout . createSequentialGroup ()
                         . addComponent ( jRadioButtonBookIndex ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   23 ,  javax . swing . GroupLayout . PREFERRED_SIZE )
                         . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED )
                         . addComponent ( jRadioButtonBookTitle ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   23 ,  javax . swing . GroupLayout . PREFERRED_SIZE ))
                     . addComponent ( jButtonSearch ))
                 . addGap ( 2 ,   2 ,   2 )
                 . addComponent ( jRadioButtonGendre ))
         );

        jLabel3 . setText ( "Search result:" );

        jTextArea1 . setColumns ( 20 );
        jTextArea1 . setRows ( 5 );
        jScrollPane1 . setViewportView ( jTextArea1 );

        jMenu3 . setText ( "File" );

        jMenuItem1 . setText ( "Exit" );
        jMenuItem1 . addActionListener ( new  java . awt . event . ActionListener ()   {
             public   void  actionPerformed ( java . awt . event . ActionEvent  evt )   {
                jMenuItem1ActionPerformed ( evt );
             }
         });
        jMenu3 . add ( jMenuItem1 );

        jMenuBar2 . add ( jMenu3 );

        setJMenuBar ( jMenuBar2 );

        javax . swing . GroupLayout  layout  =   new  javax . swing . GroupLayout ( getContentPane ());
        getContentPane (). setLayout ( layout );
        layout . setHorizontalGroup (
            layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
             . addGroup ( layout . createSequentialGroup ()
                 . addContainerGap ()
                 . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
                     . addGroup ( layout . createSequentialGroup ()
                         . addComponent ( jPanel1 ,  javax . swing . GroupLayout . DEFAULT_SIZE ,  javax . swing . GroupLayout . DEFAULT_SIZE ,   Short . MAX_VALUE )
                         . addContainerGap ())
                     . addGroup ( layout . createSequentialGroup ()
                         . addGap ( 10 ,   10 ,   10 )
                         . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
                             . addComponent ( jLabel3 )
                             . addComponent ( jScrollPane1 ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   634 ,  javax . swing . GroupLayout . PREFERRED_SIZE ))
                         . addGap ( 552 ,   552 ,   552 ))))
         );
        layout . setVerticalGroup (
            layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
             . addGroup ( layout . createSequentialGroup ()
                 . addContainerGap ()
                 . addComponent ( jPanel1 ,  javax . swing . GroupLayout . PREFERRED_SIZE ,  javax . swing . GroupLayout . DEFAULT_SIZE ,  javax . swing . GroupLayout . PREFERRED_SIZE )
                 . addGap ( 23 ,   23 ,   23 )
                 . addComponent ( jLabel3 )
                 . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED )
                 . addComponent ( jScrollPane1 ,  javax . swing . GroupLayout . DEFAULT_SIZE ,   159 ,   Short . MAX_VALUE )
                 . addContainerGap ())
         );

        pack ();
     } // </editor-fold>//GEN-END:initComponents

     private   void  jMenuItem1ActionPerformed ( java . awt . event . ActionEvent  evt )   { //GEN-FIRST:event_jMenuItem1ActionPerformed
         // TODO add your handling code here:
         System . exit ( 0 );
     } //GEN-LAST:event_jMenuItem1ActionPerformed

     private   void  jRadioButtonBookTitleActionPerformed ( java . awt . event . ActionEvent  evt )   { //GEN-FIRST:event_jRadioButtonBookTitleActionPerformed
         // TODO add your handling code here:
     } //GEN-LAST:event_jRadioButtonBookTitleActionPerformed

     private   void  jRadioButtonAuthorIndexActionPerformed ( java . awt . event . ActionEvent  evt )   { //GEN-FIRST:event_jRadioButtonAuthorIndexActionPerformed
         // TODO add your handling code here:
     } //GEN-LAST:event_jRadioButtonAuthorIndexActionPerformed

     private   void  jButtonSearchActionPerformed ( java . awt . event . ActionEvent  evt )   { //GEN-FIRST:event_jButtonSearchActionPerformed
         // TODO add your handling code here
       
     
         String  strAuthorame =   "" ;
         if   ( jRadioButtonAuthorIndex . isSelected ()){
             // Search by Author Index
             int  index ;
            index  =   Integer . parseInt ( jTextFieldSearch . getText ());
             if   ( lib . searchOnAuthorIndex ( index ))   {
                 // Update Author's information
                 Author  author  =  lib . getAuthorOnIndex ( index );
                jTextArea1 . setText ( author . toString ());
             }
             else   {   // author not found - setup empty fields
                  strAuthorame  =   "*** NOT FOUND ***" ;

             jTextArea1 . setText ( strAuthorame );
             }
             /* After searching on Author Index we also setup currentBook Index */
             if   ( lib . getCurrentBookIndex ()   !=   - 1 )   {
                 Book  book ;
                book  =  lib . getBookOnIndex ( lib . getCurrentBookIndex ());

              jTextArea1 . setText ( book . toString ());
             }
             else   {   // no more books not found with this author
            strAuthorame =   "" ;
          jTextArea1 . setText ( "*** NOT FOUND ***" );
             }
         }
         /* Search by Book Index */
         else   if   ( jRadioButtonBookIndex . isSelected ())   {
             // Search by Author Index
             int  index ;
            index  =   Integer . parseInt ( jTextFieldSearch . getText ());
             if   ( lib . searchOnBookIndex ( index ))   {
                 // Update Book information
                 Book  book  =  lib . getBookOnIndex ( index );
                 String  bk  =  book . toString () + "\n" ;

                 Author  author  =  lib . getAuthorOnIndex ( lib . getCurrentAuthorIndex ());
              bk  +=  author . toString ();
               jTextArea1 . setText ( bk );
             }
             else   {   // Book not found
                   String  strTitle  = ( "*** NOT FOUND ***" );

          jTextArea1 . setText ( strTitle );
             }
         }
         /*
         * Search by BOOK TITLE 
         */
         else   if   ( jRadioButtonBookTitle . isSelected ()){
             String  title  =  jTextFieldSearch . getText ();
             /* If book found */
             if   ( lib . searchOnBookTitle ( title )){
                 int  index  =  lib . getCurrentBookIndex ();
                 // Update Book information
                 Book  book  =  lib . getBookOnIndex ( index );
                String  strTitle  = ( book . getTitle (). toString ()) + "\n" ;
               strTitle  +=   ( book . getGendre (). toString ()) + "\n" ;
                 Author  author  =  lib . getAuthorOnIndex ( lib . getCurrentAuthorIndex ());
                strTitle  +=  author . toString () + "\n" ;
                 Address  address  =  author . getAddress ();
                strTitle  +=  address . toString ();
                jTextArea1 . setText ( strTitle );
             }
             else   {   // Book not found (no more books found)
                 String  strTitle  = ( "*** NOT FOUND ***" );
                    jTextArea1 . setText ( strTitle );
             }
         }
         /*
         * Search by BOOK GENDRE
         */
         else   if   ( jRadioButtonGendre . isSelected ()){
             String  gendre  =  jTextFieldSearch . getText ();
             /* If book found */
             if   ( lib . searchOnBookGendre ( gendre )){
                 int  index  =  lib . getCurrentBookIndex ();
                 // Update Book information
                 Book  book  =  lib . getBookOnIndex ( index );
                 String   strTitle  = ( book . toString ())   +   "\n" ;

                 Author  author  =  lib . getAuthorOnIndex ( lib . getCurrentAuthorIndex ());
                  strTitle  += ( author . toString ())   +   "\n" ;

                 Address  address  =  author . getAddress ();
                strTitle  += ( address . toString ())   +   "\n" ;
               strTitle  += ( book . getGendre (). toString ())   +   "\n" ;

              jTextArea1 . setText ( strTitle );

             }
             else   {   // Book not found (no more books found)
                   String  strTitle  = ( "*** NOT FOUND ***" );
                    jTextArea1 . setText ( strTitle );
             }
         }

        
     } //GEN-LAST:event_jButtonSearchActionPerformed

     private   void  jRadioButtonBookIndexActionPerformed ( java . awt . event . ActionEvent  evt )   { //GEN-FIRST:event_jRadioButtonBookIndexActionPerformed
         // TODO add your handling code here:
} //GEN-LAST:event_jRadioButtonBookIndexActionPerformed

     /*
     * Reset search results
     */
     /**
     *  @param  args the command line arguments
     */
     public   static   void  main ( String  args [])   throws   IOException   {
         /*
         * Read library file
         */
        lib  =   new   Library ();   // use constructor without filename
        lib . readLibrary ();   // try to read and parse data file
        
         /*
         * Set the Nimbus look and feel
         */
         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
         /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
         try   {
             for   ( javax . swing . UIManager . LookAndFeelInfo  info  :  javax . swing . UIManager . getInstalledLookAndFeels ())   {
                 if   ( "Nimbus" . equals ( info . getName ()))   {
                    javax . swing . UIManager . setLookAndFeel ( info . getClassName ());
                     break ;
                 }
             }
         }   catch   ( ClassNotFoundException  ex )   {
            java . util . logging . Logger . getLogger ( LibraryUI . class . getName ()). log ( java . util . logging . Level . SEVERE ,   null ,  ex );
         }   catch   ( InstantiationException  ex )   {
            java . util . logging . Logger . getLogger ( LibraryUI . class . getName ()). log ( java . util . logging . Level . SEVERE ,   null ,  ex );
         }   catch   ( IllegalAccessException  ex )   {
            java . util . logging . Logger . getLogger ( LibraryUI . class . getName ()). log ( java . util . logging . Level . SEVERE ,   null ,  ex );
         }   catch   ( javax . swing . UnsupportedLookAndFeelException  ex )   {
            java . util . logging . Logger . getLogger ( LibraryUI . class . getName ()). log ( java . util . logging . Level . SEVERE ,   null ,  ex );
         }
         //</editor-fold>

         /*
         * Create and display the form
         */
        java . awt . EventQueue . invokeLater ( new   Runnable ()   {

             public   void  run ()   {
                 new   LibraryUI (). setVisible ( true );
             }
         });
     }
     // Variables declaration - do not modify//GEN-BEGIN:variables
     private  javax . swing . ButtonGroup  buttonGroup1 ;
     private  javax . swing . ButtonGroup  buttonGroup2 ;
     private  javax . swing . JButton  jButtonSearch ;
     private  javax . swing . JLabel  jLabel1 ;
     private  javax . swing . JLabel  jLabel2 ;
     private  javax . swing . JLabel  jLabel3 ;
     private  javax . swing . JMenu  jMenu1 ;
     private  javax . swing . JMenu  jMenu2 ;
     private  javax . swing . JMenu  jMenu3 ;
     private  javax . swing . JMenuBar  jMenuBar1 ;
     private  javax . swing . JMenuBar  jMenuBar2 ;
     private  javax . swing . JMenuItem  jMenuItem1 ;
     private  javax . swing . JPanel  jPanel1 ;
     private  javax . swing . JRadioButton  jRadioButtonAuthorIndex ;
     private  javax . swing . JRadioButton  jRadioButtonBookIndex ;
     private  javax . swing . JRadioButton  jRadioButtonBookTitle ;
     private  javax . swing . JRadioButton  jRadioButtonGendre ;
     private  javax . swing . JScrollPane  jScrollPane1 ;
     private  javax . swing . JTextArea  jTextArea1 ;
     private  javax . swing . JTextField  jTextFieldSearch ;
     // End of variables declaration//GEN-END:variables

}

Title.java

Title.java

package   Book ;

/*
 * class Title - represents a book title
 */
public   class   Title   {
     String  title ;
     /*
     * Title() - empty constructor 
     */
     public   Title (){
        title  =   new   String ();
     }
     /*
     * Title(string) - initialize title with string
     */
     public   Title ( String  t ){
        title  =  t ;
     }
     /*
     * getTitle - get title
     */
     public   String  getTitle (){
         return  title ;
     }
     /* 
     * setTitle - set title
     */
     public   void  setTitle ( String  t ){
        title  =  t ;
     }
     /* 
     * isTitle - return true ig title matches
     */
     public   boolean  isTitle ( String  s ){
         return  s . equalsIgnoreCase ( title );
     }
     /*
     * matchTitle - return true if 'n' is a substring of title
     */
     public   boolean  matchTitle ( String  n ){
         return  title . matches ( n );
     }
    @ Override
     public   String  toString (){
         return  title ;
     }
}