• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Finding best deal of mall program in java

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 4347
40
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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




 
Marshal
Posts: 79969
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79969
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
     
    You are HERE! The other map is obviously wrong. Better confirm with this tiny ad:
    Gift giving made easy with the permaculture playing cards
    https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
    reply
      Bookmark Topic Watch Topic
    • New Topic