aspose file tools*
The moose likes Beginning Java and the fly likes Library/Book assignment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Library/Book assignment" Watch "Library/Book assignment" New topic
Author

Library/Book assignment

loni gashi
Greenhorn

Joined: Dec 11, 2012
Posts: 11
Hi!. I'm going to ask for a long question so if anyone has time to respond I will appreciate it. I have this assignment but i'm really stuck in some parts. Here is the assignment

Create class Book that modulates a book and has two attributes : name(String) and ISBN(int) that is
read-only. Create class Library that modulates an library and has two attributes: name(String) and books(array of type book)

Class Book:
a) Create constructor that gets two parameters (name, ISBN) and initialize them.
b) Offer get and set methods for class attributes
c) If name is empty or ISBN is smaller than zero(0), throw an LibraryException with a clear
message on why user can't create Book instance
d) Offer method that represent object like String(toString). The format should be:
ISBN: name
e) Offer method that compares for equality two objects of type Book.
Notice: two objects of type book are equal if they have ISBN attribute equal

Class Library:
a) Create constructor of this class that gets as parameters name of the Library and
number of books in the library. The Library should have at least 500 books. If it
has less than 500 books throw an LibraryException whith the message that there aren't
enough books
b) Offer method addBook that make possible to save the book in array of books. If the
book exist or it doesn't have space in array throw an LibraryException with the message that
the book exist or there isn't enough space.

c) Offer method indexOf(Book book) that returns value of index where book is located.
If the book isn't there than return -1.

d) Offer main() method and create instance of class Library with name "DanBrown" and
the possibility to save 750 books. Chose three books and add them in this library.
Also in main method handle all LibraryExtension cases

Class LibraryException:
Create this specific Exception that will be used in Book and Library classes.



Below are codes of three classes that I tried to do so if anyone has time please check them and if you can give me some hints on how to continue. Thanks







Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39888
    
  28
  • 1: Inconsistent indentation.
  • 2: Why are youthrowing an Exception if the title is empty and not when it is null?
  • 3: Are ISBNs ints? They have 10 digits, so cannot always fit into an int. Query that with your instructor.
  • 4: A read‑only field should be marked final.
  • 5: Give your Exception class 4 constructors to match those in the Exception class.
  • There is bound to be more, but I have to go now.
    Winston Gutkowski
    Bartender

    Joined: Mar 17, 2011
    Posts: 8251
        
      23

    loni gashi wrote:Hi!. I'm going to ask for a long question so if anyone has time to respond I will appreciate it. I have this assignment but i'm really stuck in some parts. Here is the assignment:
    ....
    Below are codes of three classes that I tried to do so if anyone has time please check them and if you can give me some hints on how to continue.

    It's very difficult to advise anything until we know what the problem is. What exactly are the issues you have?

    Apart from what Campbell already said, and this business about "read-only", which would seem to conflict with the request for "setters" - but that's a problem with the requirements, not you - I can't see a lot to advise on.

    Winston

    Isn't it funny how there's always time and money enough to do it WRONG?
    Articles by Winston can be found here
    fred rosenberger
    lowercase baba
    Bartender

    Joined: Oct 02, 2003
    Posts: 11480
        
      16

    Campbell Ritchie wrote:
  • 3: Are ISBNs ints? They have 10 digits, so cannot always fit into an int. Query that with your instructor.

  • actually, ISBNs are now 13 digits.

    And the old, 10-digit ones could have an 'X' as the last character.

    Now, it was only a check-digit, so you could store the 9-digits and compute the last on-the-fly...


    There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 39888
        
      28
    However many digits they have, they are not really ints. But it says int in the question, so we are stuck with it.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Library/Book assignment