Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 27

Thread: Help With My Library Program please.

  1. #1
    Member
    Join Date
    Sep 2012
    Location
    Philippines
    Posts
    46
    My Mood
    Cheeky
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Help With My Library Program please.

    here's my beta program, where the user can search,rent, and borrow books. but it's only virtual memory, but that's okay. but my problem is it still needs an "add book function" and i have no idea on how i can do that. i'm a still a student and a beginner in java, so please bear with me...




    Here's my Code:


    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /**
     *
     * @author Jaymark
     */
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Color;
    public class Book
    {
        String title;
        boolean borrowed;
     
        public Book(String bookTitle) 
        {
            title = bookTitle;
            borrowed = false ;
        }
     
        public void borrowed() 
        {
            borrowed = true;
        }
     
     
        public void returned() 
        {
            borrowed = false;
        }
     
        public boolean isBorrowed() 
        {
            return ((borrowed) ? true : false);
        }
     
        public String getTitle() 
        {
            return title;
        }
    }
     
     
    class Library
    {
        JFrame myFrame = new JFrame("Library");
        JLabel jLabel1 = new JLabel("***JhayJheDiegz Books***");
        JLabel jLabel2 = new JLabel("2nd Floor S-205, Science Centrum Building,");
        JLabel jLabel3 = new JLabel("Colegio de Dagupan, Arellano St. Dagupan City");
        JButton	jButton1 = new JButton("Search");
        JButton	jButton2 = new JButton("Rent");
        JButton	jButton3 = new JButton("Return");
        JButton jButton4 = new JButton("About");
        FlowLayout layout = new FlowLayout(FlowLayout.CENTER);
        Font font = new Font("Serif", Font.BOLD, 20);
     
     
        private int pressed;
     
        Book book1 = new Book("Hunger Games");
        Book book2 = new Book("Catching	Fire");
        Book book3 = new Book("Mocking Jay");
        Book book4 = new Book("The Da Vinci	Code");
        Book book5 = new Book("Harry Potter	and	The	Sorcerer's Stone");
        Book book6 = new Book("Harry Potter	and	The	Chamber	of Secrets");
        Book book7 = new Book("Harry Potter	and	The	Prisoner of	Azkaban");
        Book book8 = new Book("Harry Potter	and	The	Goblet of Fire");
        Book book9 = new Book("Harry Potter	and	The	Order of The Phoenix");
        Book book10	= new Book("Harry Potter and The Half-blood	Prince");
        Book book11	= new Book("Harry Potter and The Deathly Hallows");
     
        String[] bookName =	{"Hunger Games", "Catching Fire", "Mocking Jay", "The Da Vinci Code", "Harry Potter	and	The	Sorcerer's Stone",
            "Harry Potter and The Chamber of Secrets", "Harry Potter and The Prisoner of Azkaban", "Harry Potter and The Goblet	of Fire",
            "Harry Potter and The Order	of The Phoenix", "Harry	Potter and The Half-blood Prince", "Harry Potter and The Deathly Hallows"};
     
        String[] bookAuthor	= {"Suzanne	Collins", "Suzanne Collins", "Suzanne Collins",	"Dan Brown", "J.K. Rowling", "J.K. Rowling", 
                "J.K. Rowling",	"J.K. Rowling",	"J.K. Rowling",	"J.K. Rowling",	"J.K. Rowling"};
     
        String[] bookPublisher = {"Scholastic Press", "Scholastic Press", "Scholastic Press", "Doubleday Group", "Arthur A.	Levine Books", 
                "Arthur	A. Levine Books", "Arthur A. Levine	Books",	"Arthur	A. Levine Books", "Arthur A. Levine	Books",	"Arthur	A. Levine Books", 
                    "Arthur	A. Levine Books" };
     
        int[] bookID	= {1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011};
     
        public Library()
        {
            myFrame.setBounds(485,425, 305,200);
            myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            myFrame.setVisible(true);
            myFrame.setLayout(layout);
     
            JPanel jPanel = new JPanel();
     
            jButton1.addActionListener(new searchButton());
            jButton2.addActionListener(new rentButton());
            jButton3.addActionListener(new returnButton());
            jButton4.addActionListener(new aboutButton());
     
            jButton1.setToolTipText("Search Book");
            jButton2.setToolTipText("Rent Book");
            jButton3.setToolTipText("Return Book");
            jButton4.setToolTipText("About Our Program");
     
            myFrame.add(jLabel1);
            myFrame.add(jLabel2);
            myFrame.add(jLabel3);
            myFrame.add(jButton1);
            myFrame.add(jButton2);
            myFrame.add(jButton3);
            myFrame.add(jButton4);
     
            jLabel1.setFont(font);
            myFrame.getContentPane().setBackground(Color.LIGHT_GRAY);      
        }
     
        public void searchBook()
        {
        	String searchInput = JOptionPane.showInputDialog(null, "Enter Search Query: ", "Book Search", JOptionPane.INFORMATION_MESSAGE);
     
        	int x;
        	boolean found = false;
     
            try
            {
     
        	for(x=0 ; x<bookName.length ; x++)
        	{ 
        		if(searchInput.equalsIgnoreCase(bookName[x])) 
        		{
        			JOptionPane.showMessageDialog(null, "Book Found !" + "\nTitle: " + bookName[x] + "\nAuthor: " + bookAuthor[x] + 
        				"\nPublisher: " + bookPublisher[x] + "\nBook ISBN: " + bookID[x] , "Book Search", JOptionPane.INFORMATION_MESSAGE);
     
        				found = true;		
        		}	
     
        	}
     
        	    if(!found)
        		{
        			JOptionPane.showMessageDialog(null, "BOOK NOT FOUND !" , "Book Search", JOptionPane.ERROR_MESSAGE);
        		}
     
            }
     
            catch(Exception e)
            {
     
            }
     
        }
     
        public void rentBook()
        {
        	try
        	{
     
        	int rentEntry;
     
        	String a = JOptionPane.showInputDialog(null, "Enter Book ID: ", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
        	rentEntry = Integer.parseInt(a);
     
     
     
        	if(rentEntry == bookID[0] && book1.isBorrowed() == false)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Book Available!" + "\nTitle: " + bookName[0] + "\nAuthor: " + bookAuthor[0] + 
        			"\nPublisher: " + bookPublisher[0] + "\nISBN: " + bookID[0] + "\nRent?", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
     
        			if(pressed == JOptionPane.YES_OPTION)
        			{
        				JOptionPane.showMessageDialog(null, "Book Rented ! Thank You ! ", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
        				book1.borrowed();
        			}
        	}
     
        	else if(rentEntry == bookID[0] && book1.isBorrowed() == true)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Book Unavailable !" + "\nTry Again?", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			rentBook();
        		}
        	}
     
        	else if(rentEntry == bookID[1] && book2.isBorrowed() == false)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Book Available!" + "\nTitle: " + bookName[1] + "\nAuthor: " + bookAuthor[1] + 
        			"\nPublisher: " + bookPublisher[1] + "\nISBN: " + bookID[1] + "\nRent?", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
     
        			if(pressed == JOptionPane.YES_OPTION)
        			{
        				JOptionPane.showMessageDialog(null, "Book Rented ! Thank You ! ", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
        				book2.borrowed();
        			}
        	}
     
        	else if(rentEntry == bookID[1] && book2.isBorrowed() == true)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Book Unavailable !" + "\nTry Again?", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			rentBook();
        		}
        	}
     
        	else if(rentEntry == bookID[2] && book3.isBorrowed() == false)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Book Available!" + "\nTitle: " + bookName[2] + "\nAuthor: " + bookAuthor[2] + 
        			"\nPublisher: " + bookPublisher[2] + "\nISBN: " + bookID[2] + "\nRent?", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
     
        			if(pressed == JOptionPane.YES_OPTION)
        			{
        				JOptionPane.showMessageDialog(null, "Book Rented ! Thank You ! ", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
        				book3.borrowed();
        			}
        	}
     
        	else if(rentEntry == bookID[2] && book3.isBorrowed() == true)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Book Unavailable !" + "\nTry Again?", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			rentBook();
        		}
        	}
     
        	else if(rentEntry == bookID[3] && book4.isBorrowed() == false)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Book Available!" + "\nTitle: " + bookName[3] + "\nAuthor: " + bookAuthor[3] + 
        			"\nPublisher: " + bookPublisher[3] + "\nISBN: " + bookID[3] + "\nRent?", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
     
        			if(pressed == JOptionPane.YES_OPTION)
        			{
        				JOptionPane.showMessageDialog(null, "Book Rented ! Thank You ! ", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
        				book4.borrowed();
        			}
        	}
     
        	else if(rentEntry == bookID[3] && book4.isBorrowed() == true)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Book Unavailable !" + "\nTry Again?", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			rentBook();
        		}
        	}
     
        	else if(rentEntry == bookID[4] && book5.isBorrowed() == false)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Book Available!" + "\nTitle: " + bookName[4] + "\nAuthor: " + bookAuthor[4] + 
        			"\nPublisher: " + bookPublisher[4] + "\nISBN: " + bookID[4] + "\nRent?", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
     
        			if(pressed == JOptionPane.YES_OPTION)
        			{
        				JOptionPane.showMessageDialog(null, "Book Rented ! Thank You ! ", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
        				book5.borrowed();
        			}
        	}
     
        	else if(rentEntry == bookID[4] && book5.isBorrowed() == true)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Book Unavailable !" + "\nTry Again?", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			rentBook();
        		}
        	}
     
        	else if(rentEntry == bookID[5] && book6.isBorrowed() == false)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Book Available!" + "\nTitle: " + bookName[5] + "\nAuthor: " + bookAuthor[5] + 
        			"\nPublisher: " + bookPublisher[5] + "\nISBN: " + bookID[5] + "\nRent?", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
     
        			if(pressed == JOptionPane.YES_OPTION)
        			{
        				JOptionPane.showMessageDialog(null, "Book Rented ! Thank You ! ", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
        				book6.borrowed();
        			}
        	}
     
        	else if(rentEntry == bookID[5] && book6.isBorrowed() == true)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Book Unavailable !" + "\nTry Again?", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			rentBook();
        		}
        	}
     
        	else if(rentEntry == bookID[6] && book7.isBorrowed() == false)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Book Available!" + "\nTitle: " + bookName[6] + "\nAuthor: " + bookAuthor[6] + 
        			"\nPublisher: " + bookPublisher[6] + "\nISBN: " + bookID[6] + "\nRent?", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
     
        			if(pressed == JOptionPane.YES_OPTION)
        			{
        				JOptionPane.showMessageDialog(null, "Book Rented ! Thank You ! ", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
        				book7.borrowed();
        			}
        	}
     
        	else if(rentEntry == bookID[6] && book7.isBorrowed() == true)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Book Unavailable !" + "\nTry Again?", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			rentBook();
        		}
        	}
     
        	else if(rentEntry == bookID[7] && book8.isBorrowed() == false)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Book Available!" + "\nTitle: " + bookName[7] + "\nAuthor: " + bookAuthor[7] + 
        			"\nPublisher: " + bookPublisher[7] + "\nISBN: " + bookID[7] + "\nRent?", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
     
        			if(pressed == JOptionPane.YES_OPTION)
        			{
        				JOptionPane.showMessageDialog(null, "Book Rented ! Thank You ! ", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
        				book8.borrowed();
        			}
        	}
     
        	else if(rentEntry == bookID[7] && book8.isBorrowed() == true)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Book Unavailable !" + "\nTry Again?", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			rentBook();
        		}
        	}
     
        	else if(rentEntry == bookID[8] && book9.isBorrowed() == false)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Book Available!" + "\nTitle: " + bookName[8] + "\nAuthor: " + bookAuthor[8] + 
        			"\nPublisher: " + bookPublisher[8] + "\nISBN: " + bookID[8] + "\nRent?", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
     
        			if(pressed == JOptionPane.YES_OPTION)
        			{
        				JOptionPane.showMessageDialog(null, "Book Rented ! Thank You ! ", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
        				book9.borrowed();
        			}
        	}
     
        	else if(rentEntry == bookID[8] && book9.isBorrowed() == true)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Book Unavailable !" + "\nTry Again?", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			rentBook();
        		}
        	}
     
        	else if(rentEntry == bookID[9] && book10.isBorrowed() == false)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Book Available!" + "\nTitle: " + bookName[9] + "\nAuthor: " + bookAuthor[9] + 
        			"\nPublisher: " + bookPublisher[9] + "\nISBN: " + bookID[9] + "\nRent?", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
     
        			if(pressed == JOptionPane.YES_OPTION)
        			{
        				JOptionPane.showMessageDialog(null, "Book Rented ! Thank You ! ", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
        				book10.borrowed();
        			}
        	}
     
        	else if(rentEntry == bookID[9] && book10.isBorrowed() == true)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Book Unavailable !" + "\nTry Again?", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			rentBook();
        		}
        	}
     
        	else if(rentEntry == bookID[10] && book11.isBorrowed() == false)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Book Available!" + "\nTitle: " + bookName[10] + "\nAuthor: " + bookAuthor[10] + 
        			"\nPublisher: " + bookPublisher[10] + "\nISBN: " + bookID[10] + "\nRent?", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
     
        			if(pressed == JOptionPane.YES_OPTION)
        			{
        				JOptionPane.showMessageDialog(null, "Book Rented ! Thank You ! ", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
        				book11.borrowed();
        			}
        	}
     
        	else if(rentEntry == bookID[10] && book11.isBorrowed() == true)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Book Unavailable !" + "\nTry Again?", "Rent Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			rentBook();
        		}
        	}
     
        	else
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "BOOK NOT FOUND IN OUR CATALOGUE !" + "\nTry Again?");
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			rentBook();
        		}
        	}
     
        	}
     
        	catch(Exception e)
        	{
     
     
        	}		
        }
     
        public void returnBook()
        {
        	try
        	{
     
        	int returnEntry;
     
        	String a = JOptionPane.showInputDialog(null, "Enter Book ID: ", "Return Book", JOptionPane.INFORMATION_MESSAGE);
        	returnEntry = Integer.parseInt(a);
     
        	if(returnEntry == bookID[0] && book1.isBorrowed() == true)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Return Book?", "Return Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			JOptionPane.showMessageDialog(null, "Book Returned ! Thank You !");
        			book1.returned();
        		}
        	}
     
        	else if(returnEntry == bookID[0] && book1.isBorrowed() == false)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "You cannot Return a Book that is not Borrowed !" + "\nTry Again?", "Return Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			returnBook();
        		}
        	}
     
        	else if(returnEntry == bookID[1] && book2.isBorrowed() == true)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Return Book?", "Return Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			JOptionPane.showMessageDialog(null, "Book Returned ! Thank You !");
        			book2.returned();
        		}
        	}
     
        	else if(returnEntry == bookID[1] && book2.isBorrowed() == false)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "You cannot Return a Book that is not Borrowed !" + "\nTry Again?", "Return Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			returnBook();
        		}
        	}
     
        	else if(returnEntry == bookID[2] && book3.isBorrowed() == true)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Return Book?", "Return Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			JOptionPane.showMessageDialog(null, "Book Returned ! Thank You !");
        			book3.returned();
        		}
        	}
     
        	else if(returnEntry == bookID[2] && book3.isBorrowed() == false)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "You cannot Return a Book that is not Borrowed !" + "\nTry Again?", "Return Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			returnBook();
        		}
        	}
     
        	else if(returnEntry == bookID[3] && book4.isBorrowed() == true)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Return Book?", "Return Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			JOptionPane.showMessageDialog(null, "Book Returned ! Thank You !");
        			book4.returned();
        		}
        	}
     
        	else if(returnEntry == bookID[3] && book4.isBorrowed() == false)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "You cannot Return a Book that is not Borrowed !" + "\nTry Again?", "Return Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			returnBook();
        		}
        	}
     
        	else if(returnEntry == bookID[4] && book5.isBorrowed() == true)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Return Book?", "Return Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			JOptionPane.showMessageDialog(null, "Book Returned ! Thank You !");
        			book5.returned();
        		}
        	}
     
        	else if(returnEntry == bookID[4] && book5.isBorrowed() == false)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "You cannot Return a Book that is not Borrowed !" + "\nTry Again?", "Return Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			returnBook();
        		}
        	}
     
        	else if(returnEntry == bookID[5] && book6.isBorrowed() == true)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Return Book?", "Return Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			JOptionPane.showMessageDialog(null, "Book Returned ! Thank You !");
        			book6.returned();
        		}
        	}
     
        	else if(returnEntry == bookID[5] && book6.isBorrowed() == false)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "You cannot Return a Book that is not Borrowed !" + "\nTry Again?", "Return Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			returnBook();
        		}
        	}
     
        	else if(returnEntry == bookID[6] && book7.isBorrowed() == true)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Return Book?", "Return Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			JOptionPane.showMessageDialog(null, "Book Returned ! Thank You !");
        			book7.returned();
        		}
        	}
     
        	else if(returnEntry == bookID[6] && book7.isBorrowed() == false)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "You cannot Return a Book that is not Borrowed !" + "\nTry Again?", "Return Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			returnBook();
        		}
        	}
     
        	else if(returnEntry == bookID[7] && book8.isBorrowed() == true)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Return Book?", "Return Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			JOptionPane.showMessageDialog(null, "Book Returned ! Thank You !");
        			book8.returned();
        		}
        	}
     
        	else if(returnEntry == bookID[7] && book8.isBorrowed() == false)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "You cannot Return a Book that is not Borrowed !" + "\nTry Again?", "Return Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			returnBook();
        		}
        	}
     
        	else if(returnEntry == bookID[8] && book9.isBorrowed() == true)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Return Book?", "Return Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			JOptionPane.showMessageDialog(null, "Book Returned ! Thank You !");
        			book9.returned();
        		}
        	}
     
        	else if(returnEntry == bookID[8] && book9.isBorrowed() == false)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "You cannot Return a Book that is not Borrowed !" + "\nTry Again?", "Return Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			returnBook();
        		}
        	}
     
        	else if(returnEntry == bookID[9] && book10.isBorrowed() == true)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Return Book?", "Return Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			JOptionPane.showMessageDialog(null, "Book Returned ! Thank You !");
        			book10.returned();
        		}
        	}
     
        	else if(returnEntry == bookID[9] && book10.isBorrowed() == false)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "You cannot Return a Book that is not Borrowed !" + "\nTry Again?", "Return Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			returnBook();
        		}
        	}
     
        	else if(returnEntry == bookID[10] && book11.isBorrowed() == true)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "Return Book?", "Return Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			JOptionPane.showMessageDialog(null, "Book Returned ! Thank You !");
        			book11.returned();
        		}
        	}
     
        	else if(returnEntry == bookID[10] && book11.isBorrowed() == false)
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "You cannot Return a Book that is not Borrowed !" + "\nTry Again?", "Return Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			returnBook();
        		}
        	}
     
        	else
        	{
        		pressed = JOptionPane.showConfirmDialog(null, "BOOK NOT IN OUR CATALOGUE !" + "\n Try Again?", "Return Book", JOptionPane.INFORMATION_MESSAGE);
     
        		if(pressed == JOptionPane.YES_OPTION)
        		{
        			returnBook();
        		}
        	}
     
        	}
     
        	catch(Exception e)
        	{
     
        	} 	
        }
     
        public void aboutBook()
        {
        	try
        	{
     
        	JOptionPane.showMessageDialog(null, "Authors: " + "\nJeli Quides" + "\nEmmanuel Bulawan" + "\nJaymark Dacpano" + 
        		"\n" + "\nWe made this program for our final requirement in our Java Programming 2, " + 
        			"\nThis code is written in JCreator Pro from scratch, " + 
        				"\nIf you have any questions please approach the authors mentioned above. " + "\nThank You!");
     
        	}
     
        	catch(Exception e)
        	{
     
        	}
        }
     
        class searchButton implements ActionListener
        {
        	public void actionPerformed(ActionEvent e)
        	{
        		searchBook();
        	}
     
        }
     
        class rentButton implements ActionListener
        {
        	public void actionPerformed(ActionEvent e)
        	{
        		rentBook();
        	}
     
        }
     
        class returnButton implements ActionListener
        {
        	public void actionPerformed(ActionEvent e)
        	{
        		returnBook();
        	}
     
        }
     
        class aboutButton implements ActionListener
        {
        	public void actionPerformed(ActionEvent e)
        	{
        		aboutBook();
        	}
        } 
    }
     
    class MainSystem
    {
     
        public static void main(String[] args) 
        {
            new Library();           
        }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help With My Library Program please.

    my problem is it still needs an "add book function"
    Can you describe what the add book method should do? What data will it take as its arguments and what will it do with that data?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Sep 2012
    Location
    Philippines
    Posts
    46
    My Mood
    Cheeky
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help With My Library Program please.

    Quote Originally Posted by Norm View Post
    Can you describe what the add book method should do? What data will it take as its arguments and what will it do with that data?
    the "add book function" can be displayed and can be borrowed and returned, it will take a String title,author,publisher and an int book id. but i still don't have any idea on starting this part of my code.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help With My Library Program please.

    the "add book function" can be displayed and can be borrowed and returned,
    Your description of what the add() method should do does not make sense,
    A method can not be displayed. It can display data that is in the program.
    That description sounds more like what a Book is, not what the add() method will do. A book can be displayed, borrowed and returned.
    What class will the add() method be in? You have posted several classes.

    it will take a String title,author,publisher and an int book id
    Are those the arguments that would be passed to the add() method.
    What would the add() method do with those pieces of data?
    Last edited by Norm; September 27th, 2012 at 06:48 AM.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Sep 2012
    Location
    Philippines
    Posts
    46
    My Mood
    Cheeky
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help With My Library Program please.

    Quote Originally Posted by Norm View Post
    Your description of what the add() method should do does not make sense,
    A method can not be displayed. It can display data that is in the program.
    That description sounds more like what a Book is, not what the add() method will do. A book can be displayed, borrowed and returned.
    What class will the add() method be in? You have posted several classes.


    Are those the arguments that would be passed to the add() method.
    What would the add() method do with those pieces of data?

    sorry bout that. add() method will we in a separate class, and it will accept data from the user such as the string name,author,publisher and int ID. and the add() method would store these data's in an array.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help With My Library Program please.

    There are a lot of things to think about before trying to write the method:
    What class will the add() method be in?
    Where will the array be that it stores the data in?
    Will all the data be put into a class object before putting it in the array?
    How will the add() method get the data from the user?
    Will there also be a method that will get that data for usage somewhere else in the program?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Sep 2012
    Location
    Philippines
    Posts
    46
    My Mood
    Cheeky
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help With My Library Program please.

    i want my addBook() method in a separate class like my other methods in my program,
    the array should be on the Library class of my code,
    yes data must be put in a class before the addBook() method stores it to the array,
    the addBook() method will accept data by using dialog boxes only,
    yes, the data's added will also be used in my searchBook(), rentBook(), and returnBook() methods,

    and also can i make a constructor for an array? if so how?

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help With My Library Program please.

    It the array to be update is in the Library class, should the addBook() method be in the Library class?

    arrays do not have constructors. Use the new statement to define an array. See:
    Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Member
    Join Date
    Sep 2012
    Location
    Philippines
    Posts
    46
    My Mood
    Cheeky
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help With My Library Program please.

    yes the addBook() method will be in my Library class,

    ah i see but can i turn this piece of code to an array?

    Book book1 = new Book("Hunger Games");
        Book book2 = new Book("Catching	Fire");
        Book book3 = new Book("Mocking Jay");
        Book book4 = new Book("The Da Vinci	Code");
        Book book5 = new Book("Harry Potter	and	The	Sorcerer's Stone");
        Book book6 = new Book("Harry Potter	and	The	Chamber	of Secrets");
        Book book7 = new Book("Harry Potter	and	The	Prisoner of	Azkaban");
        Book book8 = new Book("Harry Potter	and	The	Goblet of Fire");
        Book book9 = new Book("Harry Potter	and	The	Order of The Phoenix");
        Book book10	= new Book("Harry Potter and The Half-blood	Prince");
        Book book11	= new Book("Harry Potter and The Deathly Hallows");

  10. #10
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Help With My Library Program please.

    Quote Originally Posted by jaydac12 View Post
    ah i see but can i turn this piece of code to an array?

    Book book1 = new Book("Hunger Games");
        Book book2 = new Book("Catching	Fire");
        Book book3 = new Book("Mocking Jay");
        Book book4 = new Book("The Da Vinci	Code");
        Book book5 = new Book("Harry Potter	and	The	Sorcerer's Stone");
        Book book6 = new Book("Harry Potter	and	The	Chamber	of Secrets");
        Book book7 = new Book("Harry Potter	and	The	Prisoner of	Azkaban");
        Book book8 = new Book("Harry Potter	and	The	Goblet of Fire");
        Book book9 = new Book("Harry Potter	and	The	Order of The Phoenix");
        Book book10	= new Book("Harry Potter and The Half-blood	Prince");
        Book book11	= new Book("Harry Potter and The Deathly Hallows");
    Sure you can, is an array right for you? Does an array provide the kind of storage and access you need? I would vote for some type of grouping vs a bunch of same-name-numbered variables, it is up to you to decide what suits your needs.

  11. #11
    Member
    Join Date
    Sep 2012
    Location
    Philippines
    Posts
    46
    My Mood
    Cheeky
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help With My Library Program please.

    an ArrayList maybe? but how?

  12. #12
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Help With My Library Program please.

    Quote Originally Posted by jaydac12 View Post
    an ArrayList maybe? but how?
    Well that sounds like another option.
    Why don't you try them and see?
    There are plenty of Array and ArrayList usage examples on the web.

  13. #13
    Member
    Join Date
    Sep 2012
    Location
    Philippines
    Posts
    46
    My Mood
    Cheeky
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help With My Library Program please.

    if i do that the type would be "Book" not string,

  14. #14
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Help With My Library Program please.

    Quote Originally Posted by jaydac12 View Post
    if i do that the type would be "Book" not string,
    Is that going to be a problem in your project?

  15. #15
    Member
    Join Date
    Sep 2012
    Location
    Philippines
    Posts
    46
    My Mood
    Cheeky
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help With My Library Program please.

    yes because i will be needing it to be in inside my if condition using equalsIgnoreCase()

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help With My Library Program please.

    What data do you want to compare?
    The Book class could have a method that returns a String
    or it could have a method that tested its data against a given argument.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Member
    Join Date
    Sep 2012
    Location
    Philippines
    Posts
    46
    My Mood
    Cheeky
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help With My Library Program please.

    i want to compare it to string,
    but how am i going to make an array of the Book class?

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help With My Library Program please.

    i want to compare it to string
    What is the purpose of comparing it to a String? What data does the String contain?

    Do you know how to define an array? Here's a sample:
    TheType[] varName = new TheType[<nbr of elements>];
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Member
    Join Date
    Sep 2012
    Location
    Philippines
    Posts
    46
    My Mood
    Cheeky
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help With My Library Program please.

    so that the user could input a book and the searchBook() method would find matches in the array,

    yes i know how to define an array, so it would be like this?
    Book[] bookName = new Book[10];

    so the type would be "Book" so it's not comparable to String?

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help With My Library Program please.

    "Book" so it's not comparable to String?
    That is correct.
    Can you explain the purpose of the comparison you want to make?
    What does the String contain?

    There are several ways You can use a String to find or select a Book.
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Member
    Join Date
    Sep 2012
    Location
    Philippines
    Posts
    46
    My Mood
    Cheeky
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help With My Library Program please.

    the purpose of the comparison is to find matches in the array,
    and the String contains the user's input

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help With My Library Program please.

    The Book class could have a method that would do the comparing needed to find matches with the String the user input. The method could return true if there was a match and false otherwise.

    You have not said what that String will contain. Will it be the name of the user's friend or the type of car he likes or the name of his favorite movie?
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    Member
    Join Date
    Sep 2012
    Location
    Philippines
    Posts
    46
    My Mood
    Cheeky
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help With My Library Program please.

    the String will contain the name of the book.



    i tried rewriting my code here's what i came up with:

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /**
     *
     * @author Jaymark
     */
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.awt.Color;
    public class Library
    {
     
    	ArrayList<String> bookName = new ArrayList<String>();
    	{{
    		bookName.add("Hunger Games");
    	    bookName.add("Catching Fire");
    	    bookName.add("Mocking Jay");
    	    bookName.add("The Da Vinci Code");
    	    bookName.add("Harry Potter and The Sorcerer's Stone");
    	    bookName.add("Harry Potter and The Chamber of Secrets");
    	    bookName.add("Harry Potter and The Prisoner of Azkaban");
    	    bookName.add("Harry Potter and The Goblet of Fire");
    	    bookName.add("Harry Potter and The Order of The Phoenix");
        	bookName.add("Harry Potter and The Half-blood Prince");
        	bookName.add("Harry Potter and The Deathly Hallows");	
    	}}
     
    	ArrayList<String> bookAuthor = new ArrayList<String>();
    	{{
    		bookAuthor.add("Suzanne Collins");
    		bookAuthor.add("Suzanne Collins");
    		bookAuthor.add("Suzanne Collins");
    		bookAuthor.add("Dan Brown");
    		bookAuthor.add("J.K. Rowling");
    		bookAuthor.add("J.K. Rowling");
    		bookAuthor.add("J.K. Rowling");
    		bookAuthor.add("J.K. Rowling");
    		bookAuthor.add("J.K. Rowling");
    		bookAuthor.add("J.K. Rowling");
    		bookAuthor.add("J.K. Rowling");
    	}}
     
    	ArrayList<String> bookPublisher = new ArrayList<String>();
    	{{
    		bookPublisher.add("Scholastic Press");
    		bookPublisher.add("Scholastic Press");
    		bookPublisher.add("Scholastic Press");
    		bookPublisher.add("Doubleday Group");
    		bookPublisher.add("Arthur A. Levine Books");
    		bookPublisher.add("Arthur A. Levine Books");
    		bookPublisher.add("Arthur A. Levine Books");
    		bookPublisher.add("Arthur A. Levine Books");
    		bookPublisher.add("Arthur A. Levine Books");
    		bookPublisher.add("Arthur A. Levine Books");
    		bookPublisher.add("Arthur A. Levine Books");
    	}}
     
    	boolean borrowed;
     
        JFrame myFrame = new JFrame("Library");
        JLabel jLabel1 = new JLabel("***JhayJheDiegz Books***");
        JLabel jLabel2 = new JLabel("2nd Floor S-205, Science Centrum Building,");
        JLabel jLabel3 = new JLabel("Colegio de Dagupan, Arellano St. Dagupan City");
        JButton	jButton1 = new JButton("Search");
        JButton	jButton2 = new JButton("Rent");
        JButton	jButton3 = new JButton("Return");
        JButton jButton4 = new JButton("About");
        JButton jButton5 = new JButton("Add Book To Our Library");
        FlowLayout layout = new FlowLayout(FlowLayout.CENTER);
        Font font = new Font("Serif", Font.BOLD, 20);
     
     
        private int pressed;
     
     
        public Library()
        {
            myFrame.setBounds(485,425, 305,200);
            myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            myFrame.setVisible(true);
            myFrame.setLayout(layout);
            myFrame.setResizable(false);
     
            JPanel jPanel = new JPanel();
     
            jButton1.addActionListener(new searchButton());
            jButton2.addActionListener(new rentButton());
            jButton3.addActionListener(new returnButton());
            jButton4.addActionListener(new aboutButton());
            jButton5.addActionListener(new addButton());
     
            jButton1.setToolTipText("Search Book");
            jButton2.setToolTipText("Rent Book");
            jButton3.setToolTipText("Return Book");
            jButton4.setToolTipText("About Our Program");
            jButton5.setToolTipText("Add Book");
     
            myFrame.add(jLabel1);
            myFrame.add(jLabel2);
            myFrame.add(jLabel3);
            myFrame.add(jButton1);
            myFrame.add(jButton2);
            myFrame.add(jButton3);
            myFrame.add(jButton4);
            myFrame.add(jButton5);
     
            jLabel1.setFont(font);
            myFrame.getContentPane().setBackground(Color.LIGHT_GRAY);
     
        }
     
     
        public void searchBook()
        {	 	
        	String input;
        	int x;
        	boolean found = false;
     
        	input = JOptionPane.showInputDialog(null, "Enter Name: ");
     
        	try
        	{
        	for(x=0;x<bookName.size();x++)
        	{
        		if(input.equalsIgnoreCase(bookName.get(x)))
        		{
        			JOptionPane.showMessageDialog(null, "Book Found !" + "\nTitle: " + bookName.get(x) + "\nAuthor: " + bookAuthor.get(x) + 
        				"\nPublisher: " + bookPublisher.get(x), "Book Search", JOptionPane.INFORMATION_MESSAGE);
     
        				found = true;
        		}
     
        	}
     
        	if(!found)
        	{
        		JOptionPane.showMessageDialog(null, "BOOK NOT FOUND !" , "Book Search", JOptionPane.ERROR_MESSAGE);
     
        		searchBook();
        	}
        	}
     
        	catch(Exception e)
        	{
     
        	}
     
        }
     
        public void rentBook()
        {
     
        }
     
        public void returnBook()
        {
     
        }
     
        public void aboutBook()
        {
        	try
        	{
     
        	JOptionPane.showMessageDialog(null, "Authors: " + "\nJeli Quides" + "\nEmmanuel Bulawan" + "\nJaymark Dacpano" + 
        		"\n" + "\nWe made this program for our final requirement in our Java Programming 2, " + 
        			"\nThis code is written in JCreator Pro from scratch, " + 
        				"\nIf you have any questions please approach the authors mentioned above. " + "\nThank You!");
     
        	}
     
        	catch(Exception e)
        	{
     
        	}
        }
     
        public void addBook()
        {
        	try
        	{
        		String bN;
        		String bA;
        		String bP;
     
        		bN = JOptionPane.showInputDialog(null, "Enter Book Title: ");
        		bookName.add(bN);
     
        		bA = JOptionPane.showInputDialog(null, "Enter Book Author: ");
        		bookAuthor.add(bA);
     
        		bP = JOptionPane.showInputDialog(null, "Enter Book Publisher: ");
        		bookPublisher.add(bP);
     
        		JOptionPane.showMessageDialog(null, "Book Added ! Thank You ! ");
     
        	}
     
        	catch(Exception e)
        	{
     
        	}
        }
     
        class searchButton implements ActionListener
        {
        	public void actionPerformed(ActionEvent e)
        	{
        		searchBook();
        	}
     
        }
     
        class rentButton implements ActionListener
        {
        	public void actionPerformed(ActionEvent e)
        	{
        		rentBook();
        	}
     
        }
     
        class returnButton implements ActionListener
        {
        	public void actionPerformed(ActionEvent e)
        	{
        		returnBook();
        	}
     
        }
     
        class aboutButton implements ActionListener
        {
        	public void actionPerformed(ActionEvent e)
        	{
        		aboutBook();
        	}
        }
     
        class addButton implements ActionListener
        {
        	public void actionPerformed(ActionEvent e)
        	{
        		addBook();
        	}
        } 
    }
     
    class MainSystem
    {
     
        public static void main(String[] args) 
        {	
            new Library();           
        }
    }


    now i gotta worry about how am i going to set the Book if it is Borrowed or Returned.
    Last edited by jaydac12; September 28th, 2012 at 10:46 PM.

  24. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help With My Library Program please.

    Where is the Book class?

    The action listener classes have the wrong names. The names look like the names for a button, not a listener.

    Also posted at http://www.daniweb.com/software-deve...y-program-help
    Last edited by Norm; September 29th, 2012 at 07:42 AM.
    If you don't understand my answer, don't ignore it, ask a question.

  25. #25
    Member
    Join Date
    Sep 2012
    Location
    Philippines
    Posts
    46
    My Mood
    Cheeky
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help With My Library Program please.

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /**
     *
     * @author Jaymark
     */
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.awt.Color;
    public class Book
    {
        String title;
        String author;
        String publisher;
        int isbn;
        boolean borrowed;
     
        public Book(String bookTitle) 
        {
            title = bookTitle;
            borrowed = false;
        }
     
        public void borrowed() 
        {
            borrowed = true;
        }
     
     
        public void returned() 
        {
            borrowed = false;
        }
     
        public boolean isBorrowed() 
        {
            return ((borrowed) ? true : false);
        }
     
        public void setAuthor(String bookAuthor)
        {
        	author = bookAuthor;
        }
     
        public void setPublisher(String bookPublisher)
        {
        	publisher = bookPublisher;
        }
     
        public void setIsbn(int bookIsbn)
        {
        	isbn = bookIsbn;
        }
     
        public String getTitle() 
        {
            return title;
        }
     
        public String getAuthor() 
        {
            return author;
        }
     
        public String getPublisher() 
        {
            return publisher;
        }
     
        public int getIsbn() 
        {
            return isbn;
        }
    }
    class Library
    {
    	// How Do i add author, publisher and book id here?
    	ArrayList<Book> bookName = new ArrayList<Book>();
     
    	{{
    		bookName.add(new Book("Hunger Games"));
    		bookName.add(new Book("Catching Fire"));
    		bookName.add(new Book("Mocking Jay"));
    	}}
     
        JFrame myFrame = new JFrame("Library");
        JLabel jLabel1 = new JLabel("***JhayJheDiegz Books***");
        JLabel jLabel2 = new JLabel("2nd Floor S-205, Science Centrum Building,");
        JLabel jLabel3 = new JLabel("Colegio de Dagupan, Arellano St. Dagupan City");
        JButton	jButton1 = new JButton("Search");
        JButton	jButton2 = new JButton("Rent");
        JButton	jButton3 = new JButton("Return");
        JButton jButton4 = new JButton("About");
        JButton jButton5 = new JButton("Add Book To Our Library");
        FlowLayout layout = new FlowLayout(FlowLayout.CENTER);
        Font font = new Font("Serif", Font.BOLD, 20);
     
     
        private int pressed;
     
     
        public Library()
        {
            myFrame.setBounds(485,425, 305,200);
            myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            myFrame.setVisible(true);
            myFrame.setLayout(layout);
            myFrame.setResizable(false);
     
            JPanel jPanel = new JPanel();
     
            jButton1.addActionListener(new searchButton());
            jButton2.addActionListener(new rentButton());
            jButton3.addActionListener(new returnButton());
            jButton4.addActionListener(new aboutButton());
            jButton5.addActionListener(new addButton());
     
            jButton1.setToolTipText("Search Book");
            jButton2.setToolTipText("Rent Book");
            jButton3.setToolTipText("Return Book");
            jButton4.setToolTipText("About Our Program");
            jButton5.setToolTipText("Add Book");
     
            myFrame.add(jLabel1);
            myFrame.add(jLabel2);
            myFrame.add(jLabel3);
            myFrame.add(jButton1);
            myFrame.add(jButton2);
            myFrame.add(jButton3);
            myFrame.add(jButton4);
            myFrame.add(jButton5);
     
            jLabel1.setFont(font);
            myFrame.getContentPane().setBackground(Color.LIGHT_GRAY);
     
        }
     
     
        public void searchBook()
        {	 	
        	String input;
        	int x;
        	boolean found = false;
     
        	input = JOptionPane.showInputDialog(null, "Enter Name: ");
     
        	try
        	{
        	for(x=0;x<bookName.size();x++)
        	{
        		if(input.equalsIgnoreCase(bookName.get(x).getTitle()))
        		{
        			                                              //the getAuhtor() method outputs null, how do i add data for the author?
        			JOptionPane.showMessageDialog(null, "Book Found !" + "\nTitle: " + bookName.get(x).getTitle() + "\n" + bookName.get(x).getAuthor(), 
        				"Book Search", JOptionPane.INFORMATION_MESSAGE);
     
        				found = true;
        		}
     
        	}
     
        	if(!found)
        	{
        		JOptionPane.showMessageDialog(null, "BOOK NOT FOUND !" , "Book Search", JOptionPane.ERROR_MESSAGE);
     
        		searchBook();
        	}
        	}
     
        	catch(Exception e)
        	{
     
        	}
     
        }
     
        public void rentBook()
        {
        	for(int x = 0; x<bookName.size();x++)
        	{
        		JOptionPane.showMessageDialog(null, bookName.get(x).getTitle() + "\n" + bookName.get(x).getAuthor());
        	}		
        }
     
        public void returnBook()
        {
     
        }
     
        public void aboutBook()
        {
        	try
        	{
     
        	JOptionPane.showMessageDialog(null, "Authors: " + "\nJeli Quides" + "\nEmmanuel Bulawan" + "\nJaymark Dacpano" + 
        		"\n" + "\nWe made this program for our final requirement in our Java Programming 2, " + 
        			"\nThis code is written in JCreator Pro from scratch, " + 
        				"\nIf you have any questions please approach the authors mentioned above. " + "\nThank You!");
     
        	}
     
        	catch(Exception e)
        	{
     
        	}
        }
     
        public void addBook()
        {
        	try
        	{
        		String bN;
     
        		bN = JOptionPane.showInputDialog(null, "Enter Book Title: ", "Add Book", JOptionPane.QUESTION_MESSAGE);
     
     
     
        		JOptionPane.showMessageDialog(null, "Book Added ! Thank You ! ");
     
        	}
     
        	catch(Exception e)
        	{
        		JOptionPane.showMessageDialog(null, "Please Eneter Valid ISBN !" , "Invalid Book ISBN", JOptionPane.ERROR_MESSAGE);
     
        		addBook();
        	}
     
        }
     
        class searchButton implements ActionListener
        {
        	public void actionPerformed(ActionEvent e)
        	{
        		searchBook();
        	}
     
        }
     
        class rentButton implements ActionListener
        {
        	public void actionPerformed(ActionEvent e)
        	{
        		rentBook();
        	}
     
        }
     
        class returnButton implements ActionListener
        {
        	public void actionPerformed(ActionEvent e)
        	{
        		returnBook();
        	}
     
        }
     
        class aboutButton implements ActionListener
        {
        	public void actionPerformed(ActionEvent e)
        	{
        		aboutBook();
        	}
        }
     
        class addButton implements ActionListener
        {
        	public void actionPerformed(ActionEvent e)
        	{
        		addBook();
        	}
        } 
    }
     
    class MainSystem
    {
     
        public static void main(String[] args) 
        {	
            new Library();           
        }
    }


    How Do i add author, publisher and book id here?
    ArrayList<Book> bookName = new ArrayList<Book>();


    the getAuhtor() method outputs null, how do i add data for the author?

Page 1 of 2 12 LastLast

Similar Threads

  1. [SOLVED] Simple Library Program / Need feedback.
    By ziplague in forum What's Wrong With My Code?
    Replies: 22
    Last Post: May 2nd, 2014, 09:03 PM
  2. 1.7 JRE library error?
    By colbol89 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 27th, 2011, 07:18 AM
  3. Where to place my own library?
    By hexwind in forum Java Theory & Questions
    Replies: 3
    Last Post: June 22nd, 2011, 06:25 AM
  4. how to use SteelSeries library?
    By aang in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 22nd, 2010, 12:57 PM
  5. library
    By b109 in forum Java Theory & Questions
    Replies: 2
    Last Post: May 3rd, 2010, 05:32 AM