PROGRAMMING PROJECT 7, 8, 9 on page 179 of your textbook. Read the problem over carefully. I am considering use of project 7 as the main feature, 8 and 9 for extra credit.

 

 

Write a program that draws a bar graph of the given table.

ANALYSIS

Data Requirements

Problem Constant

the bar width

Problem Input

the five possible grades

the number of students that got each grade

Problem Output

a histogram

Relevant Formulas and Relationships

bar height = 5 * the number of students with that grade

Identify the Classes

application class GradeHistogram.

JOptionPane class to be used for interactive input/output

String class for message to be used by JOptionPane method

 

Class GradeHistogram

Data Fields Attribute

x1 top left corner of rectangle for grade A

y1

x2 top left corner of rectangle for grade B

y2

x5 top left corner of rectangle for grade F

y5

numA number of students with grade A

numB number of students with grade B

numC number of students with grade C

numD number of students with grade D

numF number of students with grade F

Methods Behavior

paint() draws a grade histogram of the given data

Classes Used

Graphics

Algorithm for paint()

  1. Set the color for the first bar of the graph.
  2. Draw a rectangle for grade "A" using method fillRect().
  3. Repeat steps 1.-2. for each grade "B" through "F".
  4. Draw a label for the grade and the number of students with that grade for each rectangle in the bar graph.

 

 

HTML file for the GradeHistogram applet

<HTML>

<applet code = GradeHistogram.class width = 300 height = 300>

</applet>

</HTML>