Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Finding best deal of mall program in java

 
Vivek Jain
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone provide me this program?

Write a program to find best deal on a product in a shopping mall. Shops carry different products at different prices.

Main Requirements:
1.Mall data should be defined and read from an xml/flat file.
2.Allow entering product name on command line to find the best deal.
3.Print the store name, product name, and the price as a result on the console.
4.Program should continue with a prompt for the next product name. Word END should end the program.

Thanks in Advance!
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by free phone:
Can anyone provide me this program? ...

No. But we can help you write it. What have you done so far, and where are you stuck?

("free phone," welcome to JavaRanch! Please check your private messages by clicking on My Private Messages. Thanks!)
[ October 17, 2007: Message edited by: marc weber ]
 
Vivek Jain
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've created XML file which conains data as shown below:
<Walmart>
<ProdInfo name="Shirt" price="$45">
<ProdInfo name="Pant" price="$45">
</Walmart>
<Kohls>
<ProdInfo name="Shirt" price="$35">
<ProdInfo name="Coat" price="$65">
</Kohls>

Now, I really don't know how to store them & how to compare for least values. Whether I should save them in hastable with Walmart_Shirt as key & value as its price for all the nodes, or how should I proceed?

Thanks!
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of thinking about how to do it, think about what you want it to do first. That is, write some code that calls methods that don't exist yet and imagine how it would work. Maybe:

That gives some strong hints about how findBestPrice should work. You could make a first version that just says:

Seriously, make a test class and a Mall class that do no more than that. Show us what you make. Then we'll take the next step. This is a lot more fun than designing and writing hundreds of lines of code before you try and see how it works. Take tiny steps, keep it fun.
 
Scott Selikoff
author
Saloon Keeper
Posts: 4014
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"John Machlane"

Please review our naming policy again. In short, you may not pick names that are obviously fictiuous (yes, we've all see Die Hard).
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15284
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"John" - Your name is still not according to the JavaRanch policy.

Please check your private messages. You can see them by clicking My Private Messages.
 
Sankari Palani
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basic requirements:
Write your code in Java.
Program should run from command line.
There is no need to develop any GUI components, unless you think we will be impressed by it.


Problem
Write a program to find best deal on a product in a shopping mall. Shops carry different products at different prices.

Main Requirements:
1. Mall data should be defined and read from an xml/flat file.
2. Allow entering product name on command line to find the best deal.
3. Print the store name, product name, and the price as a result on the console.
4. Program should continue with a prompt for the next product name. Word END should end the program.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Here is the answer




 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

In view of this:
We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
. . . which is written at the top of this page, I would usually delete that solution. But after 4 years, maybe I can safely leave it. Please don’t post complete solutions again.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just looking at your code, I can see some things I would change:
  • use of System.exit()
  • Indentation: you are using tab and space together. Always use spaces.
  • It looks a lot better (as you can see now I have changed it) if you use the code button Only there appears to be a fault which occasionally changes < to ><. Don’t know why.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic