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 7.  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 in class.
  2. Edit the Big Java Review Wiki on ANGEL, adding answers to three stars worth of the review exercises from chapter 7. Be sure to carefully follow the instructions for doing this that are posted on the Wiki. Ideally you should try to mentally answer all of the Review Exercises.
  3. Programming:
    1. Your programming work for this assignment must be done in the TypesAndDecisions project which you should check out from your SVN repository into Eclipse. 

    2. (2) Add to the LargeFacts class a bigFact() method that uses BigIntegers. See the TODO comments in the file for details.
    3. (2) Using a for loop and the charAt() method of String, complete the four TODO items in the StringsAndChars class.
    4. (1) Edit the main() method of ScannerExample to print appropriate prompts for the user.
    5. (15) Create a class CubicPlot. Its constructor should take eight (yes, eight!) arguments:
      • top, left — the top-left coordinates for a rectangle on which the CubicPlot object will draw the plot.
      • width, height — the width and height of the rectangle on which the the CubicPlot object will draw the plot.
      • a, b, c, d — the coefficients of the equation y = ax3 + bx2 + cx + d, that the class will plot
      Your new class should include a constructor, and 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. One pixel on the screen represents one x or y unit in the graphing coordinate system.  A more sophisticated system would allow the user to specify scale factors in the x and y directions, but you do not have to do that.
      2. The origin of the plotted graph should be in the center of the rectangle described by top, left, width, and height.
      3. The plotted graph should display x- and y-axes. You do not need to include tick marks on the axes.
      4. Use String’s format() method and Graphics2D’s drawString() method to display the equation on the graph.
      5. Use a loop to calculate the y value for each integer x from -width/2 to width/2. Plot the graph by drawing a line from the previous point calculated to the next point. (You’ll have to calculate the first point before 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. Test your code with several different sets of values for a, b, c, and d.  You might want to plot the same functions in Maple (forcing the x- and y-ranges of Maple's plots to be the same as in your Java window) for comparison purposes.
      7. Edit the code so that the coefficient values are read from user input using a Scanner object instead of being hardcoded.
      8. Bonus: (3) clip the plot so that it doesn’t extend beyond the bounds of the rectangle given by top, left, width, and height.
      The figure below gives an example plot (without clipping, no bonus for me). It uses the numbers in the "commented out" section of PlotComponent.java.
      Sample CubicPlot output

Turn-in Instructions

We will grade your Wiki contributions using ANGEL. Turn-in your programming work by committing it to your SVN repository.