Completely lost, creating a bar graph

• February 28th, 2011, 04:36 AM
lairel
Completely lost, creating a bar graph
i wrote this code:
Code Java:

``` import java.text.DecimalFormat; import java.util.Scanner;   public class salary { public static void main(String[] args) { //declare variables int years = 1, maxValue; double salary = 500; double averageSalary = 0; double totalPay = 0;   //Create decimal formatter DecimalFormat formatter = new DecimalFormat("\$0,000.00");   //create a scanner Scanner keyboard = new Scanner(System.in);   //Receive the number of years to work System.out.print("How many years will you work? "); maxValue = keyboard.nextInt();   //Determine is years are correct if (years < 1 || years > 60) { System.out.println("Years must be between 1 and 60"); } else { //Return Salary table System.out.println("Year \t\tSalary Earned"); System.out.println("--------------------------");   for (years = 1; years <= maxValue; years++) { System.out.println(years + "\t\t" + (formatter.format(salary *= 2))); totalPay += salary; averageSalary = totalPay / years; }   //display totals System.out.println("\nTotal pay: " + (formatter.format(totalPay))); System.out.println("Average salary: " + (formatter.format(averageSalary))); } } }```

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 :
Quote:

----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
Quote:

----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.
• February 28th, 2011, 06:18 AM
DanBrown
Re: Completely lost, creating a bar graph
Comment this line
Quote:

// System.out.println(years + "\t\t" + (formatter.format(salary *= 2)));
Code Java:

```System.out.print(years); salary *= 2; int last = (int)salary; int step = 1000; for(int start=1000;start<=last;start=start+step){ System.out.print("*"); }   System.out.println();```