• 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

How to take an integer out of an Arraylist, and graph it?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ideally what I'd like to do is take the price integer (the 4th one) out of an ArrayList, add it to profit, and then show the profit over time as a graph. If it's difficult, I'd like to change it so it just prints out the
profit, and number of cars sold. Adding the cars sold part would be easy, just add a new integer and everytime the carSold() method runs, add 1 to it. Or even better, maybe show how many of each type of car
is sold...I'd like to do that.
Edit: I figured out how to add it to the ArrayList! Now i just need to figure out how to graph it!
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't quite understand what it is that you want to graph, but I think that's part of your problem too. So what I'd suggest is this: Draw a fairly detailed diagram of what one of those graphs might look like, and then start figuring out what data you would need to produce that graph. Once you have done that, the next step is to modify your code to get the relevant data and store it in a suitable data structure.
 
Kai Viz
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:I don't quite understand what it is that you want to graph, but I think that's part of your problem too. So what I'd suggest is this: Draw a fairly detailed diagram of what one of those graphs might look like, and then start figuring out what data you would need to produce that graph. Once you have done that, the next step is to modify your code to get the relevant data and store it in a suitable data structure.



I want to take the ArrayList (profitList) and graph the profit inside of it. So like, X would be the amount of carsSold. and Y would be the profit. Thinking of that now, I suppose I wouldn't need an ArrayList for this type of graph.

So then I'd take the code: for (Profit profit : profitList) {
newTotal += profit.getProfit();

That would get me the total amount of profit. Under the carSold method I'd just add soldCars = soldCars + 1; and make the soldCars variable global so I can call it under the printProfits() method or the new graphing method...if I can figure out how to graph it.

The problem is: I have no idea what code to use to graph something. It doesn't have it in my book: (Objects first with Java)

If I can't get it to graph, then the printProfits() variable will look something like this:


I just don't think that's good enough for my final project. But it'll have to do if I can't get the graph to work. Oh well, back to google-fu and waiting for a response! (hope this clears up what I wanted)
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, so your question is more like how to produce a graph? Well, your only tool is System.out, right? Not a powerful tool for sure, but it isn't impossible to draw graphs with it. And yes, they aren't going to be nice graphs but it's still not out of the question.

Your graphs are going to be limited to characters you can produce from the keyboard, pretty much. In fact you could mock one up in your text editor just by typing comments into Java code with enough spaces and with some non-space characters to indicate points in the graph. Characters like X or * or maybe O could be good choices. There's also the | character if you need vertical bars and either - or _ for horizontal bars.

Does that help? If so then your first step is to try to produce something not too horrible-looking from the keyboard. Don't worry about writing code to produce a graph from Java data just yet, just figure out how to make a graph to start with.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Well, your only tool is System.out, right? Not a powerful tool for sure, but it isn't impossible to draw graphs with it. And yes, they aren't going to be nice graphs but it's still not out of the question.


@Kai: If you're going to plot this on System.out, one thing that might be worth considering is rotating the graph 90% from how you would normally produce it - the reason being that it's a lot easier to produce horizontal "bars" than vertical ones. So if I was doing this, my first cut would be to produce a graph with Y as # of cars sold. and X as profit.

HIH

Winston
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic