CSSE 220 – Object-Oriented Software Development

Homework 6

Objectives

More practice creating, documenting, and testing classes based on a given public interface. Practice reading console input and formatting text. Practice reading detailed specifications.

Tasks

  1. Complete the assigned reading for the next session: Chapter 5. (See schedule for topics to focus on.) As you read, see if you can answer the self-check questions. If there is something you do not understand, make note of it so you can ask about it.
  2. Complete the assessment exercise over this reading on ANGEL (under Lessons → Assignments).
  3. Programming: The reading for next session is a bit long, so we’ll try to mostly complete the programming in class.
    1. Your programming work for this assignment must be done in the FundamentalDataTypes project inside Eclipse. Use the SVN Repository Exploring perspective to check out this project, then switch back to the Java perspective.

    2. Add a bigFact() method to the LargeFacts class so that it uses BigIntegers. See the TODO comments in the file for details.
    3. Using a for loop and the charAt() method of String, complete the four TODO items in the StringsAndChars class.
    4. Edit the main() method of ScannerExample to print appropriate prompts for the user.
    5. 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. In PlotComponent, uncomment the call the CubicPlot’s constructor before beginning.
      1. The origin of the plotted graph should be in the center of the rectangle described by top, left, width, and height.
      2. The plotted graph should display x- and y-axes. You do not need to include tick marks on the axes.
      3. Use String’s format() method and Graphics2D’s drawString() method to display the equation on the graph.
      4. Edit PlotComponent so that the coefficient values are read using a Scanner instead of being hardcoded.
      5. Begin this now, but finish this step for HW 7: Use a loop to calculate the y value for each integer x from -width to width. Plot the graph by drawing a 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.
      6. 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): Sample CubicPlot output

Turn-in Instructions

Turn in your programming work by committing it to your SVN repository.