0% found this document useful (0 votes)
33 views

J Ex

To develop an online bookstore application using Java, the key classes and packages that would need to be created include: Packages for accounts, inventory, and executable code. Classes for User (abstract), Customer, Administrator, Book, Category (abstract), FictionCategory, NonFictionCategory, MysteryCategory, Bookstore, and ShoppingCart. Interfaces for IBook, ICategory, IBookstore, and IShoppingCart. The User class would serve as a blueprint for Customer and Administrator classes. Bookstore and ShoppingCart classes would manage inventory and allow purchasing. Exception handling, abstraction, and polymorphism would also be implemented.

Uploaded by

mushayidominic
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

J Ex

To develop an online bookstore application using Java, the key classes and packages that would need to be created include: Packages for accounts, inventory, and executable code. Classes for User (abstract), Customer, Administrator, Book, Category (abstract), FictionCategory, NonFictionCategory, MysteryCategory, Bookstore, and ShoppingCart. Interfaces for IBook, ICategory, IBookstore, and IShoppingCart. The User class would serve as a blueprint for Customer and Administrator classes. Bookstore and ShoppingCart classes would manage inventory and allow purchasing. Exception handling, abstraction, and polymorphism would also be implemented.

Uploaded by

mushayidominic
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

you are tasked with developing an online bookstore using Java.

The application should allow to


browse and purchase books from various categories. you need to design and implement the system
using Object oriented programing.

1. Packages;

accounts has classes user.java, administrator.java, customer.java.

invetory has bookstore.java, books.java, category.java and all category classes(fiction, non-fiction,
mystery)

executable has cart.java and main.java.

2. User Class + (Customer and Administrator classes);

user auto generated id, firstname, lastname, address, phone. implement two child classes
namely(customer and administrator classes) with appropriate distinct fields e.g administrators must
have login privileges(username, role, password)and customers may further have credit points
attained at every purchase and will determine discounts in further purchases.

customer profile should also have a collection of books bought.

3. Book Class;

create a book class that represents a book with attributes such as autogenerated id, title, author,
price and isbn. implement proper encapsulation for these attributes.

4. Category Class;

create a category class that represents a category of books e.g (fiction, non-fiction, mystery)

use inheritance to ensure that each category inherits common attributes from parent class such as
name and description.

5.Bookstore Class;

create a bookstore class that manages the collection of books available for purchase

the bookstore must have an id and a location.

implement a method to add books to the store's inventory, taking into consideration quantities of
books stored.

implement a method to search for books by title or author withing specific category.

allow store administrators to manage the inventory, adding and removing books.

6. Shopping Cart;

design a shopping cart class that allows customers to add and remove a book.

the cart must have an autogenerated id, customer Id, store ID and seller Id.

it must have a list of books selected and their quantities, also, ensure that the shopping cart can
calculate the total cost of the items added.
the cart must invoke methods int he bookstore class to check whether the required quantities to be
purchased are available and reduce the stock when purchases are made.

7. Exception Handling, Abstraction and Polymorphism;

implement exception handling for scenarios like adding duplicate books to the shopping cart or
searching for a book that doesnt exist.

utilize abstraction to hide the internal implementation details of the book class while providing a
public interface to access its attributes.

implement polymorphism by creating different subclasses of category(e.g fictionCategory, non-


fictionCategory) taht override methods like getDescription.

Guidelines:

start by creating a class diagram that outlines the relationship between classes and their attribute
methods.

use appropriate exception classes for exception handling (e.g DuplicateBookException,


BookNotFoundException)

To develop an online bookstore using Java, I would follow the given


guidelines and create the following packages, classes, and interfaces:
Packages:
 accounts
 inventory
 executable
Classes:
 User (abstract)
 Customer (extends User)
 Administrator (extends User)
 Book (concrete)
 Category (abstract)
 FictionCategory (extends Category)
 NonFictionCategory (extends Category)
 MysteryCategory (extends Category)
 Bookstore (concrete)
 ShoppingCart (concrete)
Interfaces:
 IBook
 ICategory
 IBookstore
 IShoppingCart
User Class:
The User class is an abstract class that provides a blueprint for the
Customer and Administrator classes. It contains the following attributes:
 id (auto-generated)
 firstName
 lastName
 address
 phone
The Customer class extends the User class and adds the following
attributes:
 creditPoints (attained at every purchase)
 collection of books bought
The Administrator class extends the User class and adds the following
attributes:
 username
 role
 password
Book Class:
The Book class represents a book with the following attributes:
 id (auto-generated)
 title
 author
 price
 ISBN
It implements proper encapsulation for these attributes and provides getter
and setter methods for accessing them.
Category Class:
The Category class is an abstract class that provides a blueprint for the
FictionCategory, NonFictionCategory, and MysteryCategory classes. It
contains the following attributes:
 name
 description
The FictionCategory, NonFictionCategory, and MysteryCategory classes
extend the Category class and provide their own implementations of the
getDescription() method.
Bookstore Class:
The Bookstore class manages the collection of books available for purchase.
It contains the following attributes:
 id
 location
It provides methods for adding and removing books from the inventory,
searching for books by title or author within a specific category, and
managing the inventory.
Shopping Cart Class:
The ShoppingCart class allows customers to add and remove books from
their cart. It contains the following attributes:
 id (auto-generated)
 customerId
 storeId
 sellerId
 list of books selected
 quantities of books selected
It provides methods for calculating the total cost of the items added,
checking if the required quantities are available, and reducing the stock
when purchases are made.
Exception Handling:
I would implement exception handling for scenarios like adding duplicate
books to the shopping cart or searching for a book that doesn't exist. For
example, I would use the DuplicateBookException and
BookNotFoundException classes to handle these scenarios.
Abstraction:
I would utilize abstraction to hide the internal implementation details of the
Book class while providing a public interface to access its attributes.
Polymorphism:
I would implement polymorphism by creating different subclasses of
Category (e.g., FictionCategory, NonFictionCategory) that override methods
like getDescription(). This would allow me to create objects of different
types and treat them uniformly, making the code more flexible and
reusable.

public class Book {

private String title;

private String author;

private int pages;


private double price;

public Book(String title, String author, int pages, double price) {

this.title = title;

this.author = author;

this.pages = pages;

this.price = price;

public String getTitle() {

return title;

public void setTitle(String title) {

this.title = title;

public String getAuthor() {

return author;

public void setAuthor(String author) {

this.author = author;

public int getPages() {

return pages;

public void setPages(int pages) {

this.pages = pages;
}

public double getPrice() {

return price;

public void setPrice(double price) {

this.price = price;

public class User {

private String name;

private String email;

private List<Category> categories;

// Constructor

public User(String name, String email) {

this.name = name;

this.email = email;

this.categories = new ArrayList<>();

// Getters and Setters

public String getName() {

return name;

public void setName(String name) {

this.name = name;
}

public String getEmail() {

return email;

public void setEmail(String email) {

this.email = email;

public List<Category> getCategories() {

return categories;

public void setCategories(List<Category> categories) {

this.categories = categories;

// Add a category to the user's list of categories

public void addCategory(Category category) {

categories.add(category);

// Remove a category from the user's list of categories

public void removeCategory(Category category) {

categories.remove(category);

public class Category {

private String name;


private String description;

// Constructor

public Category(String name, String description) {

this.name = name;

this.description = description;

// Getters and Setters

public String getName() {

return name;

public void setName(String name) {

this.name = name;

public String getDescription() {

return description;

public void setDescription(String description) {

this.description = description;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy