Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

creating a bar graph

 
jamie keene
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what have you tried so far?
 
jamie keene
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sounds like what you need. Hint use a loop.
 
jamie keene
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a while loop?
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally I would go for a for-loop but you can do it with a while loop.
 
jamie keene
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic