• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Quick Sort and Bar Chart using Java

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Im trying to create java program in quick sort, displaying below orders from small to large quantities

Example: need to enter 5 orders of the following

OrderID Item ID Date Category Item price quantity
Order1 item1 10-10-2011 personal care dove shampoo 8 100
Order1 item2 10-10-2011 food knorr 5 200
total 300
Order2 item3 10-10-2011 food walls 3 200
order2 item1 10-10-2011 personal care dove 8 150
total 350
order3 item4 10-10-2011 beverage lipton 1.5 250
order3 item5 10-10-2011 home care sunlight 4 300
total 550

Once all info gathered, required to produce 2 bar charts showing revenue:
1) Category(y-axis) and Quantity(x-axis).
2) Order Id(y axis) and quantity (x axis)


Any advise on how to produce chart using java, showing the revenue from smallest to largest? im not allowed to use 3rd party library. Thank you for your help.
below is the code:
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unformatted code is hard to read and understand. Please click on the button to UseCodeTags
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What exactly do you mean by "chart" - an image with a graphical chart, or would a printout on the console suffice that shows maybe one "*" for each 10 or 50 units of revenue? The former would be rather involved (at least w/o the use of 3rd party packages, which would make it pretty easy), whereas the latter would be comparatively simple.

Edit: On second thought, seeing that you generate HTML, something like this may do the trick: http://www.juiceanalytics.com/writing/lightweight-visualization-in-html/
 
Nicky Dee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:What exactly do you mean by "chart" - an image with a graphical chart, or would a printout on the console suffice that shows maybe one "*" for each 10 or 50 units of revenue? The former would be rather involved (at least w/o the use of 3rd party packages, which would make it pretty easy), whereas the latter would be comparatively simple.

Edit: On second thought, seeing that you generate HTML, something like this may do the trick: http://www.juiceanalytics.com/writing/lightweight-visualization-in-html/




Perhaps in graphical chart? if I choose sort based on Order Id,it should look like chartOrderID.jpg. if choose based on product category, should look like chartProduct.jpg


Whoever edited my code into UseCodeTags, thanks so much will do that next time
chartOrderID.jpg
[Thumbnail for chartOrderID.jpg]
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That was me :-)

Creating a graphical chart is not trivial without the help of 3rd party libraries. Are you familiar with Java image processing, or Java GUIs? If not, then you'll have a somewhat lengthy learning curve on your hands. I'm not even sure which terms to search for that do not lead to results utilizing some library or other.
 
Bartender
Posts: 3323
86
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you should look at how to use for loops to fill your 'array'.
 
Nicky Dee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:That was me :-)

Creating a graphical chart is not trivial without the help of 3rd party libraries. Are you familiar with Java image processing, or Java GUIs? If not, then you'll have a somewhat lengthy learning curve on your hands. I'm not even sure which terms to search for that do not lead to results utilizing some library or other.




"Results of the sorting are also showed in a chart. Using third party library to create a chart is NOT ALLOWED. You can choose other chart type such as pie or line".. sigh Java GUI I'm on a beginner level.
 
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nicky Dee wrote:"Using third party library to create a chart is NOT ALLOWED. You can choose other chart type such as pie or line"



That's one nasty requirement. As Ulf said, creating charts without using third party libraries is very difficult. I hope you can use HTML5 because that's your best option considering the limitations that have been imposed on you. You'll have to research how to create 2D drawings on a <canvas> element.
 
Ranch Hand
Posts: 133
Hibernate Oracle Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IMO it would be possible using JApplet. (obviously, if it is allowed) .
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All those different array indices look very error‑prone to me. Also giving names like A B C to numbers is confusing (and they should be lower‑case).

The thing about arrays suggests a design problem to me. If your input is in array format, maybe you should have your figures in an array. And the rows should maybe be objects which encapsulate several figures.
 
Ranch Hand
Posts: 41
Eclipse IDE Clojure Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apologies for the comment I am about to make, because it is slightly off-topic... but wouldn't it be better to use a switch to replace lines 44 ~ 183? Just omit some breaks and gg, right? :p



or perhaps you could try a for-loop if you don't fancy switches
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should adjust the size of the array to the number of data to be entered.
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

or perhaps you could try a for-loop if you don't fancy switches


It's not really a case of "if you don't fancy switches", if every element of the array is to be filled with the same thing then the only sensible solution is to use a loop such as a for-loop (as per my earlier post). If the contents of the array vary depending on the value of nooforder then a switch statement is the way to go as you can't use a loop and a switch statement is definitely preferable to the if-else statements.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic