Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java coding 4 classes are needed 1- Inventory class The Inventory class will track the state of the inventory of your system. It should keep

Java coding

4 classes are needed

1- Inventory class

The Inventory class will track the state of the inventory of your system. It should keep track of the type and quantity of each Product, as well as provide methods to access and modify this information. The following functionalities should be available in any given Inventory object: - Get the amount of stock for a given Product ID (Note: it is possible the Product does not exist in the Inventory!). - Add a specified amount of stock for a given Product to the inventory (Note: new Products can be added!). - Remove a specified amount of stock for a given Product ID from the inventory (Note: you cannot have negative stock, and you cannot delete Products from the Inventory; if a Products stock reaches 0, leave it.). - Get information on a Product given a Product ID. - Initialize the Inventory; set the contents of the Inventory to some default values upon object creation.

2- ShppingCart class

The ShoppingCart class is very similar to the Inventory class in purpose. A ShoppingCart will keep track of the state of the users shopping cart. It should maintain the contents that the user adds to it. Remember, the user can also remove items. ShoppingCarts are maintained for every user by the StoreManager class as previously mentioned. 3- The StoreView Class The StoreView class will manage the GUI for your system. the StoreView class must contain the main() method (i.e. the entry point of the program). Each instance of the StoreView class contains a StoreManager and a unique cartID used to identify the user of the system. In our case, each StoreView instance will have a unique cartID. You can choose how the StoreView class will obtain the StoreManager and cartID (you can pass them via a constructor if you want). However, the cartID should be generated by the StoreManager class You should think of each instance of the StoreView class as a separate user browsing the store. Like multiple users on the internet browsing an online store. However, your store is obviously much simpler.

4- The storeManager Class The StoreManager will also be managing user ShoppingCarts & Inventory. Each user that connects to the store (new StoreView instance) should have their own unique ShoppingCart. If a user adds something to their cart, the Products stock in the store Inventory should be decreased accordingly. A user can also remove items from their cart. Note that if the user removes a product from the shopping cart, the inventory must also be updated accordingly. Upon request, the StoreManager should return a new, unique cartID. This means StoreManager should be keeping track of cartIDs in some way. It could be as simple as having a counter that increments every time a new ShoppingCart is made. A user needs to be able to checkout once they are ready This method should return the total and summary of the items in the cart (print it for the user to see). You can choose to disconnect the user at this point or reset the cart up to you! If the user quits before checking out, any items in the cart should be returned to the Inventory stock. Note: quitting means the user entered quit, not your program suddenly closes;

Now that we will be implementing the UI for the store, you need some way to get the information needed to drive this UI. StoreManager should have some methods that return needed information about ShoppingCarts, or available Products. The StoreView class will be using this information to populate the UI for the user. Remember, all communication by the StoreView class must be done with the StoreManager only!

Questions 1. What kind of relationship is the StoreView and StoreManager relationship? Explain. 2. Due to their behavioral similarity, would it make sense to have ShoppingCart extend Inventory, or the other way around? Why or why not? 3. What are some reasons you can think of for why composition might be preferable over inheritance? These do not have to be Java-specific. 4. What are some reasons you can think of for why inheritance might be preferable over composition? These do not have to be Java-specific.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions