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);
}
}
}