Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Completely lost, creating a bar graph

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Completely lost, creating a bar graph

    i wrote this code:
       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 :
    ----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.


  2. #2
    Member DanBrown's Avatar
    Join Date
    Jan 2011
    Posts
    134
    My Mood
    Confused
    Thanks
    1
    Thanked 12 Times in 12 Posts

    Default Re: Completely lost, creating a bar graph

    Comment this line
    // System.out.println(years + "\t\t" + (formatter.format(salary *= 2)));
    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();
    Thanks and Regards
    Dan Brown

    Common Java Mistakes

Similar Threads

  1. Help with Polynomial Graph Plotter and its scaling
    By sojharo in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 23rd, 2011, 06:04 PM
  2. How to make a graph like this
    By sugarhigh in forum AWT / Java Swing
    Replies: 1
    Last Post: August 27th, 2010, 09:05 AM
  3. Completely Lost in this problem(multiple methods)
    By wacarter in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 31st, 2010, 04:44 PM
  4. Completely New to Java
    By slimshadie in forum Java Theory & Questions
    Replies: 7
    Last Post: September 6th, 2009, 01:55 PM
  5. Replies: 1
    Last Post: October 7th, 2008, 07:35 AM