Input/Output: Graphics and Arrays: A Bar graph

Screen Shot 2015-02-23 at 12.19.21 AM

Classwork:
Standard Drawing

 

Write a program, BarGraph_YI.java to draw a bar graph like the one in the picture above.

Create an array of 100 random positive integer numbers between 1 and 20 inclusive. 

Find the min and max for both scales, x and y so you can determine the Xscale and Yscale for your canvas. Store in two arrays the approximate values for each of the bars in the image. Those values represent the frequency (y axis) and the value for the x coordinate. Make the width of each bar equal to 1.

Example: Bar 1: starts at 2 and the height is 5. This means 5 counts of 2.

Bar 2: starts at 4 and the height is 1. This means 1 count of 4. … and so on.

The idea behind the assignment: Use the x and y values to draw rectangles.

Suggestions: Make the Xscale and Yscale a bit larger than the min and max so the bar graph has a margin.

Tracing the trick for this assignment

Challenge: instead of drawing the bars at 2 or 3 or 4, draw then starting at 1.5, 2.5, 3.5 so the middle of the bar for 2 is on 2.

Labels are extra credit.