Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This question deals with Java class design. \
First, read the following description of an online shopping system for books:
The online system sells a range of books. Every book in the system has a unique
identifier (a positive integer), a price (represented as a real number), along with
strings representing its title, author, and publisher. In addition, every book has
an integer property representing the number of copies of that book in stock; if
the number is zero, then the book is out of stock, otherwise it is available.
Users can put books into an online shopping basket. For simplicity, we will assume that a user will only put a single copy of each book into the basket. The
shopping basket provides only the ability to add a book to the basket; at this time,
there is no support for removing a book. A book is only added to the basket if it
is (i) not already in the basket and (ii) not out of stock.
(a) Write a class definition for Book, incorporating all of the attributes mentioned above. You
should also define a public constructor for Book, which should initialise all instance fields to sensible values. The constructor should assign a unique identifier value to each instance.
You do not need to define any instance methods.
(b) Write a class definition for ShoppingBasket, incorporating the book-adding functionality mentioned above. You may assume that the Book class provides any necessary get/set methods. If one of the conditions for adding a book to the basket is violated, your implementation
should throw an IllegalArgumentException instead of adding it.
(c) Imagine that the shopping system is to be expanded to sell CDs in addition to books. Describe how you would modify the classes defined above to deal with this situation. You may
illustrate your answer with fragments of Java source code, but this is not essential

What I have tried:

Do I need to use Scanner and explain about instance variable and method declaration here in this case
Posted
Updated 12-Dec-19 22:52pm
Comments
phil.o 13-Dec-19 4:52am    
Do you provide the solvant, or do we have to bring our own?

This is your own homework, please try harder to do it yourself and ask here only specific questions.
 
Share this answer
 
Quote:

1. First, read the following description of an online shopping system for books:
2. Write a class definition for Book, incorporating all of the attributes mentioned above.
3. Write a class definition for ShoppingBasket, incorporating the book-adding functionality mentioned above.
4. Imagine that the shopping system is to be expanded to sell CDs in addition to books. Describe how you would modify the classes defined above to deal with this situation.


Start at point 1 and work your way carefully through the remaining parts. If necessary draw yourself some diagrams, and write some notes to assist you.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900