Results 1 to 3 of 3
  1. #1
    kenjiro310 is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Default create a Java program which draws a bar graph based on the input from the command lin

    I am trying to read the user input from the command line

    You are to create a Java program which draws a bar graph based on the input from the command line.

    Requirements

    1. The input is going to be organized in the following format:

    ...

    2. and are going to represent the width and height of the graph respectively.

    3. through will represent the value for each of the bars in the bar graph.

    4. The largest bar in the bar graph will span from 20 pixels from the top of the graph to the bottom.

    5. The size of the other bars are going to be relative to the largest bar. This means that if the largest bar has a value of 100, then a bar with a value of 50 is going to be half its height.

    6. There are 5 pixels between each of the bars.

    7. The color for each of the bars should be different.

    8. The width of the bars is depended on the screen size. All bars should be fully visible on the screen. The first bar in the graph should have a 5 pixel space before it and the last bar graph should have 5 pixel space after it.

    9. The program should be able to handle any number of input data.

    With the code below i am able to get the program to accept user input and use the 1st 2 elements to get the Height and Width of the Frame to adjust.

    Now i am trying to pass the rest of the input to create a bargraph

    import javax.swing.*;
    import java.util.*;

    public class ProjectOne {
    public static void main(String[] args) {
    for (int i = 0; i < args.length; i++){
    //Storing 1st 2 elements entered from the command line width and heigth
    int num1 = Integer.parseInt(args[0]);
    int num2 = Integer.parseInt(args[1]);
    //Makes new frame with title
    JFrame f = new JFrame("Project 1");
    //Close operation
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //Object of Data class
    Data p = new Data();
    //Adds info to the frame
    f.add(p);
    f.setSize(num2, num1);
    f.setVisible(true);
    }
    }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    kenjiro310 is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Default update

    How would i pass the rest of the users input after the 1st 2 elements to the class that would use the reset of the users inputs for the bargraph

Similar Threads

  1. Dynamic Create Object based on user's input?
    By diskhub in forum New To Java
    Replies: 2
    Last Post: 03-08-2011, 05:47 PM
  2. Replies: 0
    Last Post: 01-25-2011, 06:37 AM
  3. Replies: 4
    Last Post: 11-12-2010, 05:25 AM
  4. How can I create Graph(Data structure) with Java ?
    By mir.shahidul in forum Advanced Java
    Replies: 2
    Last Post: 02-10-2009, 11:19 AM
  5. How can I create Graph(Data structure) with Java
    By mir.shahidul in forum New To Java
    Replies: 4
    Last Post: 02-09-2009, 09:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •