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.
-
Java RMI: The project uses Java RMI to allow interaction between the client and server. The server exports
Product
andCart
objects, 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 theProduct
andCart
objects. -
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.
-
The server starts and reads the
products.xml
file to get the list of available products. Each product is created as aProduct
object and exported as a remote object. -
The server also creates a
Cart
object and exports it as a remote object. TheCart
object contains a list ofProduct
objects 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 eachProduct
object to display the product details. -
When the user chooses to add a product to the cart, the client calls the
addProduct()
method on theCart
object with the chosenProduct
object as the argument. -
When the user chooses to view the cart, the client calls the
viewAddedProducts()
method on theCart
object to display the products in the cart. -
The admin can also view the product details by calling the
ViewProduct()
method on eachProduct
object.
- Compile all the
.java
files. - Start the RMI registry.
- Run the
Server.java
file to start the server. - Run the
Customer.java
file to start the client. - Run the
Admin.java
file to start the admin program.
-
ProductInterface.java
: This interface defines the methods that aProduct
object must implement. -
CartInterface.java
: This interface defines the methods that aCart
object must implement. -
Server.java
: This is the server program. It reads an XML file to get the list of products, exports theProduct
andCart
objects, and binds them to the RMI registry. -
Product.java
: This class implements theProductInterface
and 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 theCartInterface
and represents a shopping cart. It has a private list ofProductInterface
objects,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 theProduct
andCart
objects in the RMI registry and allows the user to interact with them. -
Admin.java
: This is the admin program. It looks up theProduct
objects in the RMI registry and allows the admin to view the product details.