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

HW1 2014 Java

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

HW1 2014 Java

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

Object Oriented Programing (10636212)

HW1 [ OOP] (20 points)

Deadline: 15/5/2024

Create a JAVA program to model an Online Bookstore Management System. You will have 5
classes: Book, Customer, Order, Inventory, and BookstoreManagmentSystem.

Cheating from ChatGPT is totally prohibited. We can


detect it easily and you are responsible for your behavior.
Book Class:

● public Book(String title, String author, String isbn, double price, int quantity):
Constructor to initialize a new Book object with the given parameters.
● public void updateQuantity(int delta): Method to update the quantity of the book by
adding the given value.
● Getters: Methods to retrieve information about the book such as title, author, ISBN,
price, and quantity.
● @Override public String toString(): Method to provide a string representation of the
Book object.

Customer Class:

● public Customer(String name, String email, String address): Constructor to initialize a


new Customer object with the given parameters.
● public void placeOrder(Order order): Method to place an order for the customer.
● public List<Order> getOrderHistory(): Method to retrieve the order history of the
customer.
● Getters: Methods to retrieve information about the Customer.
● Setters: Methods to set information about the Customer.

Order Class:

● public Order(List<Book> items): Constructor to initialize a new Order object with the
given list of items.
● private void calculateTotalPrice(): Method to calculate the total price of the order based
on the prices of the items.
● public void updateShippingStatus(String status): Method to update the shipping status
of the order.
● ShippingStatus= {Pending or Shipped}
● @Override public String toString(): Method to provide a string representation of the
Order object.
Inventory Class:

● public Inventory(): Constructor to initialize a new Inventory object.


● public void addBook(Book book): Method to add a new book to the inventory.
● public Book findBook(String isbn): Method to find a book in the inventory based on its
ISBN. You should handle the error case with Dialog Box when the book isbn does not
exist.
● public List<Book> searchBooks(String query): Method to search for books in the
inventory based on a query string. You should handle the error case with Dialog Box
when the query about the book does not match.

Main Method (BookstoreManagementSystem):

main(String[] args): Main method to test the functionality of the classes and methods. Testing
functionality such as adding books to the inventory, searching for books, creating a customer,
placing an order, updating shipping status, and viewing order history.

You should add a full menu to interact with the system:

1. Add book

2. Search about book

3. Find a book

4. Create a customer and place an order

5. Update shipping status

6. View customer order history

You should put all classes in one package.


Example of sample result: Feel free to output the result in your own format.

Search results about “Java”:

Book{title='Java How to Program', author='Deitel and Deitel', isbn='978-0134685991',


price=29.99, quantity=50}

Order placed:

Order{orderId=1, date=Mon May 06 20:05:16 IDT 2024, items=[Book{title='Java How to


Program', author='Deitel and Deitel', isbn='978-0134685991', price=29.99, quantity=50},
Book{title='Data Structures and Algorithms', author='Alice Johnson', isbn='978-0262033848',
price=39.99, quantity=30}], totalPrice=69.97999999999999, shippingStatus='Pending'}

Order updated:

Order{orderId=1, date=Mon May 06 20:05:16 IDT 2024, items=[Book{title='Java How to


Program', author='Deitel and Deitel', isbn='978-0134685991', price=29.99, quantity=50},
Book{title='Data Structures and Algorithms', author='Alice Johnson', isbn='978-0262033848',
price=39.99, quantity=30}], totalPrice=69.97999999999999, shippingStatus='Shipped'}

Customer order history:

Order{orderId=1, date=Mon May 06 20:05:16 IDT 2024, items=[Book{title='Java How to


Program', author='Deitel and Deitel', isbn='978-0134685991', price=29.99, quantity=50},
Book{title='Data Structures and Algorithms', author='Alice Johnson', isbn='978-0262033848',
price=39.99, quantity=30}], totalPrice=69.97999999999999, shippingStatus='Shipped'}
Map and List are interfaces

● We can not create objects from interfaces, but we can create object from any class that
implements that interface.

Map<Integer, String> hashMap = new HashMap<>();

hashMap.put(1, "One");

Map<Integer, String> treeMap = new TreeMap<>();

treeMap.put(3, "Three");

Map<Integer, String> linkedHashMap = new LinkedHashMap<>();

linkedHashMap.put(5, "Five");

-----------------------

List<String> arrayList = new ArrayList<>();

arrayList.add("One");

List<String> linkedList = new LinkedList<>();

linkedList.add("Three");
import java.util.*;

public class MapAndListExample {

public static void main(String[] args) {

// Creating a Map to store employee details

Map<Integer, String> employeeMap = new HashMap<>();

// Adding some employee details to the map

employeeMap.put(1, "Ali");

employeeMap.put(2, "Mona");

// Creating a List to store employee IDs

List<Integer> employeeIds = new ArrayList<>();

// Adding employee IDs to the list

employeeIds.add(1);

employeeIds.add(2);

// Accessing values from the map using keys from the list

for (Integer id : employeeIds) {

String name = employeeMap.get(id);

System.out.println("Employee ID: " + id + ", Name: " + name);

} }}

Good Luck

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