CSSE 220 – Object-Oriented Software Development
Homework 6
Objectives
Practice creating, documenting, and testing classes based on a given public interface. More graphics and math practice. Practice with if
in Java.
Tasks
- Complete the assigned reading for today's session (Big Java, Ch. 6), according to the course schedule.
- As you read, see if you can answer the self-check questions.
- Bring your questions to class!
- Complete the assessment exercise over this reading on Moodle.
- Programming:
-
In Eclipse, checkout the Decisions project.
- Use the
SVN Repositories
view to check out this project.
- (16 points)
Write a program that translates a letter grade into a numeric grade. Letter grades are A B C D F, possibly followed by a + or -. Their numeric values are 4, 3, 2, 1, and 0. There is no F+ or F-. A + increases the numeric value by 0.3, a minus decreases it by 0.3. However an A+ has the value 4.0. All other inputs have value -1.
We’ve provided a commented-out GradeTest
JUnit test class for you. Uncomment and study the code there for clarification of the design of the Grade
class.
- (38 points, 41 possible if you do the extra credit) Create a class
CubicPlot
. Its constructor should take eight (yes, eight!) arguments:
- top, left — the top-left coordinates for a rectangle on which the class will plot
- width, height — the width and height of the rectangle on which the class will plot
- a, b, c, d — the coefficients of the equation y = ax3 + bx2 + cx + d, that the class will plot
The class should include a method drawOn(Graphics2D g)
that plots the graph as detailed below. The classes CubicPlotViewer
and PlotComponent
are provided. PlotComponent
includes a call of CubicPlot
’s constructor that we supplied to test your code. Uncomment that call.
Implement the CubicPlot
class to satisfy these conditions:
- The origin of the plotted graph should be in the center of the rectangle described by
top
, left
, width
, and height
.
- The plotted graph should display x- and y-axes. You do not need to include tick marks on the axes.
- Use
String
’s format()
method and Graphics2D
’s drawString()
method to display the equation on the graph.
- Use a loop to calculate the y value for each integer x from
-width/2
to width/2
. Plot the graph by drawing a
short line from the previous point calculated to the next point.
(You’ll have to calculate the first point outside the loop.) Be sure
to shift your plot according to the required origin. You should also
“flip” the y values when plotting so that the y-axis increases up
the screen.
- Bonus: clip the plot so that it doesn’t extend beyond the bounds given by
top
, left
, width
, and height
.
The figure below gives an example plot (without clipping, no bonus for me):
Remember, in all your code:
- Write appropriate comments:
- Javadoc comments for public fields and methods.
- Explanations of anything else that is not obvious.
- Give self-documenting variable and method names:
- Use name completion in Eclipse, Ctrl-Space, to keep typing cost low and readability high.
- Use Ctrl-Shift-F in Eclipse to format your code.
- Take care of all auto-generated TODO’s.
- Then delete the TODO comment.
- Correct ALL compiler warnings.
- Quick Fix is your friend!
Here is the grading rubric for this assignment.
Turn-in Instructions
Turn in your programming work by committing it to your SVN repository.