• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Library/Book assignment

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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







 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
  • 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.
     
    Bartender
    Posts: 10780
    71
    Hibernate Eclipse IDE Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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
     
    lowercase baba
    Posts: 13089
    67
    Chrome Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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...
     
    Campbell Ritchie
    Marshal
    Posts: 79177
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    However many digits they have, they are not really ints. But it says int in the question, so we are stuck with it.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic