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.

Results 1 to 14 of 14

Thread: Hi guys..I need some tips in creating a library programme for my Uni project

  1. #1
    Member clarky2006's Avatar
    Join Date
    Nov 2012
    Posts
    84
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Hi guys..I need some tips in creating a library programme for my Uni project

    /**
     * Write a description of class Book here.
     * 
     * @author (Michael Clark) 
     * @version (30th October 2012, version 0.1)
     */
    public class Book
    {
        // instance variables - replace the example below with your own
        private int id;
        private String author;
        private String title;
        private boolean isFiction;
     
     
        /**
         * Constructor for objects of class Book
         */
        public Book(String title, String author, int id, boolean isFiction)
        {
            // initialise instance variables
            this.id = 0;
            this.author = author;
            this.title = title;
            this.isFiction = false;
        }
     
        /**
         * Get the name of the book Author.
         * 
         */
        public String getAutor()
        {
            // put your code here
            return this.author;
        }
     
        /**
         * Get the book ID.
         */
        public int getId()
        {
            return this.id;
        }
     
        /**
         * Get the book title.
         * 
         */
        public String getTitle()
        {
            return this.title;
        }
     
        public void setAuthor(String authorName)
        {
            author = authorName;
        }
     
        public void setId(int bookId)
        {
            id = bookId;
        }
     
        public void setTitle(String bookTitle)
        {
            title = bookTitle;
        }    
     
    }

    This is the book Class, every time i click on compile, it goes into an infinite compilation.
    import java.util.ArrayList;
    /**
     * This Class would hold Membership details for the Library.
     * 
     * @author (Michael Clark) 
     * @version (30th October 2012, version 0.1)
     */
    public class Member
    {
        // instance variables - These are member object attributes/fields
        private String firstName;
        private String lastName;
        private String phoneNumber;
        private int refNumber;
     
        /**
         * Constructor for objects of class Member
         */
        public Member(String firstName, String lastName, String phoneNumber, int refNumber)
        {
            this.firstName = firstName;
            this.lastName = lastName;
            this.phoneNumber = phoneNumber;
            this.refNumber = refNumber;
     
        }
     
        /**
         * This is return method for the object firstname.
         * 
         */
        public String getfirstName()
        {
             return this.firstName;
        }
     
        /**
         * Return method for the last name.
         */
        public String getlastName()
        {
            return this.lastName;
        }
     
        /**
         * Return method for the phone number.
         */
        public String getPhoneNumber()
        {
            return this.phoneNumber;
        }
     
        /**
         * Return method for membership reference.
         */
        public int getrefNumber()
        {
            return this.refNumber;
        }
    }

    import java.util.ArrayList;
     
    /**
     * This is a model of a Library class.
     * 
     * @author (Michael Clark) 
     * @version (30th October 2012, version 0.1)
     */
    public class Library
    {
        // instance variables  
        private ArrayList<Membership> member;
        private ArrayList<Book> books;
     
        /**
         * Constructor for objects of class Library
         */
        public Library(Membership member)
        {
            // initialise instance variables
            members = new ArrayList<Membership>();
            books = new ArrayList<Book>();
        }

    This is the Library class to implement all the functionality, but really struggled here to integrate it into the rest of the classes. it also goes into an infinite compilation when I compile it.. Its a Uni project and the scenario is this =

    (1) To create a member Class that keeps a basic information about each of its members e.g first name, last name, phone number and each member is also given a unique ID(positive integer)

    (2) To create a book Class. Every book is given a unique positive integer ID which is used to track the loans. The library also records a books Author, Title, and whether its fiction or non-fiction.

    (3) The loan class. A loan is a member borrowing a particular book. So if a member comes in and borrows 3 books its considered 3 loans. the loan period for all books is 3 wks. The library records the membership ID, the book ID number, the date loaned and the date due back. So here we have to add a loan for a given member and book ID numbers. Remove a loan for a given member and book ID numbers. List all loans giving book and member details. This should hold at least 2 attributes, members ID and books ID or member and book object references.

    (4) The library Class should provide all the functionality required to maintain collections of members, books and loans. The library class should have 2 attributes of type ArrayLists one for the members and one for the books. with a constructor to create the arraylists

    Any input would be appreciated guys.. thanx


  2. #2
    Forum Admin
    Join Date
    Oct 2012
    Posts
    92
    My Mood
    Amused
    Thanks
    9
    Thanked 18 Times in 13 Posts

    Default Re: Hi guys..I need some tips in creating a library programme for my Uni project

    This is your fourth thread about the same thing. What are you doing?

  3. #3
    Member clarky2006's Avatar
    Join Date
    Nov 2012
    Posts
    84
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Hi guys..I need some tips in creating a library programme for my Uni project

    Quote Originally Posted by Admin View Post
    This is your fourth thread about the same thing. What are you doing?
    sorry mate just trying to get used to the site. Lost my bearing a bit..cheers.

  4. #4
    Member clarky2006's Avatar
    Join Date
    Nov 2012
    Posts
    84
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Hi guys..I need some tips in creating a library programme for my Uni project

    /**
     * This is the book Class and would hold information on the books 
     * collection.
     * 
     * @author (Michael Clark) 
     * @version (30th October 2012, version 0.1)
     */
    public class Book
    {
        // instance variables 
        private int bookId;
        private String author;
        private String title;
        private boolean fiction;
     
        /**
         * Constructor for objects of class Book with parameters.
         */
        public Book(int id, String author, String title, boolean fiction)
        {
            // Instance variables
            this.bookId = 0;
            this.author = author;
            this.title = title;
            this.fiction = true;
        }
     
        /**
         *  This is a default constructor method with no parameters for 
         *  the books Class.
         *
         *  
         */
         public Book()
         {
     
         }
     
        /**
         * This method is for returning the name of the books Author. 
         */
     
        public String getautor()
        {
     
            return author;
        }
     
        /**
         * This method returns the book ID.
         */
     
        public int getId()
        {
            return bookId;
        }
     
        /**
         * 
         * This method would return the Book title.
         */
        public String getTitle()
        {
            return title;
        }
     
        /**
         * 
         * This mutator method should change or set the book author's name 
         * when called.
         * 
         */
        public void setAuthor(String authorName)
        {
            author = authorName;
        }
     
        /**
         * 
         * This method sets the book ID when invoked.
         */
        public void setId(int newBookId)
        {
            bookId = newBookId;
        }
     
        /**
         * 
         * This method when invoked would prompt the user to set/change the book title 
         * by entering a string name in the parameter.
         * 
         */
        public void setTitle(String bookTitle)
        {
            title = bookTitle;
        }
     
        /**
         * This method when called would print all the book's details including the
         * book author, book ID, book title and whether its fiction or non fiction.
         * 
         */
        public void printDetails()
        {
     
     
        {
     
     
            System.out.println("bookId  "+ bookId + "#");
            System.out.println("author " + author + "#");
            System.out.println("bookTitle " + title + "#");
     
            System.out.println("?????????");
     
        }
     
    }
     
    public boolean fiction()
    {
        if(boolean == true)
        System.out.println("This book is ficion");
     
     
     
    }
     
    }

    Here is my new re-written book class, cant get the code to print if the book is fiction or non fiction.help..

    --- Update ---

    it says class "expected"?

    --- Update ---

    it says class "expected"?

  5. #5
    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: Hi guys..I need some tips in creating a library programme for my Uni project

    Quote Originally Posted by clarky2006 View Post
    ...

    --- Update ---

    it says class "expected"?

    --- Update ---

    it says class "expected"?
    Do you expect a reply to your sentence fragments?

  6. #6
    Member clarky2006's Avatar
    Join Date
    Nov 2012
    Posts
    84
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Hi guys..I need some tips in creating a library programme for my Uni project

    Quote Originally Posted by jps View Post
    Do you expect a reply to your sentence fragments?
    Finally sorted the book Class. Cheers for your input..Here is the revised code..............................

     * @author (Michael Clark) 
     * @version (30th October 2012, version 0.1)
     */
    public class Book
    {
        // instance variables - replace the example below with your own
        private int bookId;
        private String author;
        private String title;
        private boolean Fiction;
        /**
         * Constructor for objects of class Book
         */
        public Book(String title, String author, int bookId, boolean Fiction)
        {
            // initialise instance variables
            this.bookId = bookId;
            this.author = author;
            this.title = title;
            this.Fiction = Fiction;
        }
     
        public Book()
        {
     
     
        }    
     
        /**
         * Get the name of the book Author.
         * 
         */
        public String getAutor()
        {
     
            return author;
        }
     
        /**
         * Get the book ID.
         */
        public int getId()
        {
            return bookId;
        }
     
        /**
         * Get the book title.
         * 
         */
        public String getTitle()
        {
            return title;
        }
     
        public void setAuthor(String authorName)
        {
            author = authorName;
        }
     
        public void setId(int bookId)
        {
            bookId = bookId;
        }
     
        public void setTitle(String bookTitle)
        {
            title = bookTitle;
        }
     
        public void printDetails()
        {
        {
            System.out.println("book ID  "+ bookId + "#");
            System.out.println("author " + author + "#");
            System.out.println("book Title " + title + "#");
            if(Fiction)
            System.out.println("This book is Fiction");
     
            else
            System.out.println("This book is Non-Fiction");
        }
     
    }
     
    public void setToFiction()
    {
        Fiction = true;
    }
     
    public void setToNonFiction()
    {
        Fiction = false;
    }
     
    }


    --- Update ---

     * A description of class Loan here.
     * 
     * @author (Michael Clark) 
     * @version (30th October 2012, version 0.1)
     */
    public class Loan
    {
        // instance variables - replace the example below with your own
        private Member memberId;
        private Book bookId;
        private GregoreanCalendar dateLoaned;
        private GregoreanCalendar dateDueBack;
        /**
         * Constructor for objects of class Loan
         */
        public Loan()
        {
            // initialise instance 
            membershipId = memberId;
        }
     
        public GregoreanCalendar currentTime()
        {
     
        }
     
        public void returnedBook(bookref)
        {
     
        }
     
        public void search()
        {
     
        }    
    }

    Now to the loan Class. Here the attributes are member, book, gregorianCalendardateDueBack and gregorianCalendarDateLoaned. Now I need to incoporate the whole thing into the code. so when a book is returned it could be taken off the loan class and library system.
    Any suggestions or Ideas how I could go about doing this?...cheers guys..............

  7. #7
    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: Hi guys..I need some tips in creating a library programme for my Uni project

    Any suggestions or Ideas how I could go about doing this?
    Think of a way to solve the problem, and then consider all of the code you have available to take advantage of, and reusing as much code as you can try to implement the solution in code. Why don't you come up with a plan of attack first, and see how far you can get.

    Don't give in just yet, you have done a nice job so far.

  8. The Following User Says Thank You to jps For This Useful Post:

    clarky2006 (November 13th, 2012)

  9. #8
    Member clarky2006's Avatar
    Join Date
    Nov 2012
    Posts
    84
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Hi guys..I need some tips in creating a library programme for my Uni project

    Quote Originally Posted by jps View Post
    Think of a way to solve the problem, and then consider all of the code you have available to take advantage of, and reusing as much code as you can try to implement the solution in code. Why don't you come up with a plan of attack first, and see how far you can get.

    Don't give in just yet, you have done a nice job so far.
    Ha ha...I like your optimism, and encouragement, maybe you should change your name to Mr MOTIVATOR......................

  10. #9
    Member clarky2006's Avatar
    Join Date
    Nov 2012
    Posts
    84
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Hi guys..I need some tips in creating a library programme for my Uni project

     public void printDetails()
        {
        {
            System.out.println("First Name  " + firstName); "Last Name " + lastName  + phoneNumber + referenceNumber);
            System.out.println("Last Name " + lastName);
            System.out.println("Phone Number " + phoneNumber);
            System.out.println("Membership  " + referenceNumber);    
        }

    I cant get this to all print on the same line..

  11. #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: Hi guys..I need some tips in creating a library programme for my Uni project

    Quote Originally Posted by clarky2006 View Post
    I cant get this to all print on the same line..
    What does the documentation say the method println does?

    What does your favorite search engine say about printing things all on one line using java?

  12. #11
    Member clarky2006's Avatar
    Join Date
    Nov 2012
    Posts
    84
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Hi guys..I need some tips in creating a library programme for my Uni project

      public void printDetails()
        {
        {
            System.out.println("First Name:  " + firstName + "  Last Name: "  +   lastName  + "  phoneNumber: " + phoneNumber  + "  referenceNumber:  " + referenceNumber);
     
        }

    done it mate..cheers

  13. #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: Hi guys..I need some tips in creating a library programme for my Uni project

    Looks like there is an extra { in there but I get the idea. Looks good.
    See how many different ways you can print the same thing now.

  14. #13
    Member clarky2006's Avatar
    Join Date
    Nov 2012
    Posts
    84
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Hi guys..I need some tips in creating a library programme for my Uni project

    Quote Originally Posted by jps View Post
    Looks like there is an extra { in there but I get the idea. Looks good.
    See how many different ways you can print the same thing now.
    More issues trying to remove a member with their ID..But it wont let me..returns error code "int cannot be dereferenced" I dont understand that...Help!

    /**
         * Remove the member with the given reference Number
         * 
         */
        public boolean removeMember(int referenceNumber)
        {
            boolean removed = false;
            Iterator<Membership> it = members.iterator();
            while(it.hasNext() && !removed)
            {
                Membership member = it.next();
                if(referenceNumber.equals(member.getReferenceNumber()))
                {
                    removed = true;
                    it.remove();
                }
            }
            return removed;     
        }

  15. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Hi guys..I need some tips in creating a library programme for my Uni project

    returns error code "int cannot be dereferenced"
    When you get an error, please copy the full text of the compiler's error message and post it here.
    The message shows where the error happened so we can find it.


    int cannot be dereferenced
    Only references to object can be used to refer to a member of the class. Primitives like int are not objects and do not have members that can be referenced like this: refToObject.member
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Help with designing a library programme
    By clarky2006 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 8th, 2012, 05:40 AM
  2. Having Trouble Using a Project as a Library
    By snowguy13 in forum Java IDEs
    Replies: 0
    Last Post: July 5th, 2012, 08:11 PM
  3. Java Project / Library to evaluate poker hands
    By Farmer in forum Java IDEs
    Replies: 1
    Last Post: February 14th, 2012, 10:25 AM
  4. Uni project - help please :)
    By sameer in forum Java Theory & Questions
    Replies: 0
    Last Post: November 6th, 2010, 10:54 AM
  5. creating a shared library
    By navinbecse in forum Threads
    Replies: 1
    Last Post: April 9th, 2010, 07:54 AM