CS 110 Introduction to Computing
Project #1: A bar chart applet
In this project you will be writing your first independent applet, a simple bar chart. To do this, you will need to do something very much like the pie chart that we did in class. However, rather than using fillArc you will use fillRect (You can read about fillRect in the Java API http://bubo.brynmawr.edu/~gtowell/docs/api/index.html then click on java.awt in the upper left frame of the browser and then click on Graphics in the lower left frame.)
Pick an interesting and meaningful dataset with 3 or 4 points to use as the source data for your bar chart. (I will be very disappointed if anyone uses the same data.) For example, you might make a bar chart of the eye color of the people in your residence hall. Then, to be amusing, you could try to make the colors of the bars approximately the same color as people's eyes.
While creating your chart, do not forget things like: the title, the axes, the scale.
Be sure to create this chart so that it is easily resized. For instance, consider starting with a chart that fits in an applet that is 300 wide by 300 tall. It should be very easy to change the program to produce a chart that is 500 wide by 500 tall. (This change should require changing only 2 characters in you program; then saving and recompiling.)
A part of the grade will be based on the look of your bar chart.
Due Date: September 16, at the beginning of class
Submit:
- A printout of the code for your applet.
- A printout of your applet. (see note below)
- The URL of the HTML page containing your applet
- Less than 1 page containing:
- A description of your dataset
- The advantages of creating graphs by writing programs
- The disadvantages of creating graphs by writing programs
- Things which, if you knew how to do them, would have allowed you to make a nicer bar chart.
Grading: | Applet | 90 pts
|
---|
Advantages and disadvantages statement | 10pts
|
Notes
To get a printout of an applet in the lab do the following (changing XXXX as appropriate to your file names):
- in a terminal window enter: appletviewer XXXX.html &
- in a terminal window enter: import XXXX.jpg
- click once in the appletviewer window (the cursor should look kind of like a +)
- in a terminal window enter: lpr XXXX.jpg
Do not use data even similar to any suggestions in this document or that were made during class.
Extra Credit
10 points: Rather than using simple rectangles for bars use shapes that are meaningful to the dataset that you are plotting. For instance, your dataset could be the value of the coins in 4 people's pockets. Then the shapes could be cylinders representing each different coin. Alternately, the chart could be of the number of particular html tags in an html document. Then the shapes could be bigger and smaller diamonds (because < and >, which surround html tags look kind of like diamonds when placed together). Of course, this chart should use horizontal bars since the beginning and end of html tags are more horizontal than vertical. (Note: if you do this extra credit, also submit the simple verion of the applet (both image and code).)
5 points: (This is probably not worth your effort) Use the drawImage method do make a bar chart with pretty images. For instance, in the coins example above, you might use actual pictures of coins. To do this you will need to read a lot of pieces of the Java API. (To get both this and the previous extra credit you need to hand in two versions of your applet, the simple one and this one, showing each working.)
5 points: (This is probably not worth your effort.) Applets can find out for themselves the size of the window in which they appear. Read the Java API to figure out how to do his, and then do it. The result should be that your bar chart automatically sizes itself to the dimensions of the window in which it appears.