shinjitsue/RMI_XML-Shopping-Cart
Java's Remote Method Invocation (RMI) and XML parsing shopping cart system.
Java RMI Shopping Cart with XML Parsing
This project is a simple shopping cart system implemented using Java's Remote Method Invocation (RMI) and XML parsing. It simulates a shopping experience where a customer can view products, add them to a cart, and view the cart. Additionally, an admin can view the product details.
Features
-
Java RMI: The project uses Java RMI to allow interaction between the client and server. The server exports
ProductandCartobjects, and the client can call methods on these objects remotely. This allows the client to add products to the cart and view the cart without directly manipulating theProductandCartobjects. -
XML Parsing: The server reads an XML file to get the list of available products. Each product is then exported as a remote object that the client can interact with. This allows the server to easily update the list of available products by modifying the XML file.
How it Works
-
The server starts and reads the
products.xmlfile to get the list of available products. Each product is created as aProductobject and exported as a remote object. -
The server also creates a
Cartobject and exports it as a remote object. TheCartobject contains a list ofProductobjects that the customer has added to the cart. -
The client starts and displays a menu to the user. The user can choose to view the available products, view the cart, add a product to the cart, or exit the program.
-
When the user chooses to view the products, the client calls the
ViewProduct()method on eachProductobject to display the product details. -
When the user chooses to add a product to the cart, the client calls the
addProduct()method on theCartobject with the chosenProductobject as the argument. -
When the user chooses to view the cart, the client calls the
viewAddedProducts()method on theCartobject to display the products in the cart. -
The admin can also view the product details by calling the
ViewProduct()method on eachProductobject.
How to Run
- Compile all the
.javafiles. - Start the RMI registry.
- Run the
Server.javafile to start the server. - Run the
Customer.javafile to start the client. - Run the
Admin.javafile to start the admin program.
Files
-
ProductInterface.java: This interface defines the methods that aProductobject must implement. -
CartInterface.java: This interface defines the methods that aCartobject must implement. -
Server.java: This is the server program. It reads an XML file to get the list of products, exports theProductandCartobjects, and binds them to the RMI registry. -
Product.java: This class implements theProductInterfaceand represents a product in the store. It has private attributes for the product code, name, description, quantity, retail price, and store price. It also has aViewProduct()method that returns a string representation of the product details, and getters for the product attributes. -
Cart.java: This class implements theCartInterfaceand represents a shopping cart. It has a private list ofProductInterfaceobjects,addedProducts, which represents the products added to the cart. It also has methods to add a product to the cart, remove all products from the cart, and view the products in the cart. -
Customer.java: This is the client program. It looks up theProductandCartobjects in the RMI registry and allows the user to interact with them. -
Admin.java: This is the admin program. It looks up theProductobjects in the RMI registry and allows the admin to view the product details.