File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes creating a bar graph Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "creating a bar graph " Watch "creating a bar graph " New topic
Author

creating a bar graph

jamie keene
Greenhorn

Joined: Feb 15, 2011
Posts: 28


this code runs correcty as is, but how do i change it to create instead of a table with a salary a table with ***
for example
current out put would be :

----jGRASP exec: java salary
How many years will you work? 4
Year Salary Earned
--------------------------
1 $1,000.00
2 $2,000.00
3 $4,000.00
4 $8,000.00

Total pay: $15,000.00
Average salary: $3,750.00

----jGRASP: operation complete.


desired output would be

----jGRASP exec: java salary
How many years will you work? 4
Year Salary Earned
--------------------------
1 *
2 **
3 ****
4 ********

Total pay: $15,000.00
Average salary: $3,750.00

----jGRASP: operation complete.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

And what have you tried so far?


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
jamie keene
Greenhorn

Joined: Feb 15, 2011
Posts: 28
i thought i could try declaring a String variable named stars that represented *
and then take the salary/1000 and have that = the number of stars but i couldn't figure out the code for that
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

That sounds like what you need. Hint use a loop.
jamie keene
Greenhorn

Joined: Feb 15, 2011
Posts: 28
a while loop?
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Personally I would go for a for-loop but you can do it with a while loop.
jamie keene
Greenhorn

Joined: Feb 15, 2011
Posts: 28
i'm not sure how to code the for loop, i already have on in there, but how do i alter it so that every $1000 = * ?
because my current for loop is what makes the salary double

jamie keene
Greenhorn

Joined: Feb 15, 2011
Posts: 28

i know this isn't compiling right, but i don't know how to fix it so it runs right
i need to add a way to make the string "*" show up for each $1000
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

That is almost the same code as you posted earlier. Hint: number of stars = salary / 1000. Combine that with my previous hint and you'll be able to solve it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: creating a bar graph