Problem
You have to create an XML file denoting a mall with shops having products. Create a program to find the best deal on a product in the given mall. Shops carry different products at different prices.
Write your code in Java. Programs should run from command line. There is no need to develop any GUI components, unless you think we will be impressed by it!
Analysis
We will not write a GUI component. Create objects abstracting Mall, Shop, Product. Tempting as it may be to use JDOM for XML parsing, adding an extra jar for the solution is an overkill. Stick to JAXP.
Design
Mall will contain Shops. Shops will contain Products. Each Product will have an owner shop. This will maintain bidirectional relation. Bi-directionality will come in handy when out of all products in the mall with the same name, we find the least priced and call product.getOwner() to return the shop which the buyer should hit.
We also need:
- Builder for XML parsing and creating a mall object from it. Let’s call it MallBuilder make it a singleton.
- Data structure to hold and publish the best shops for all the products in the mall. So we have a BestPricer for every mall object with an internal cache of Product names and the least-priced Product objects. Remember we can navigate to a product’s owner by calling getOwner()
- A director is required to all assemble them all and run the show. ShoppingGuide can be the class that interacts with user, validates his/her choices and uses MallBuilder to create a Mall which in turn is used to create its BestPricer.
Data looks like this (click the plus sign to expand):

0 Response to “Assignment - XML, Java”