CMSI 186: Homework Assignment #5

Learning Outcomes: Students will (1) learn how to describe, explain, and use superclasses and subclasses in Java; (2) explain the mathematical notion of a function and its implementation; and (3) learn how to use looping constructs to subdivide a problem space.

Problems About Estimations

This assignment concerns a method of using randomized estimation to determine an area of a non-rectangular object. For this assignment you will make a program to calculate the amount of plywood required to construct a ramp for use in skateboarding, as discussed in class. The shape of the ramp will be given by an equation. For example, a half-pipe shape would be given by a polynomial equation.

The assignment is to make SkateRamp.java, which computes the area of the supports for the skateboard half-pipe as shown in this picture. Your program must be able to handle a description of the shape of the halfpipe using polynomials of arbitary degree, as well as trigonometric and other functions [log, exponential, etc.]. If the program is invoked incorrectly, it should, as usual, output a clear message to tell the user the proper way to run the program. Your program will be invoked as follows:

java SkateRamp args[0] args[1] args[2] … args[k-1] args[k] lowerBound upperBound percent%

where args[0] is the name of a function type; args[1] … args[k] specify the coefficients of the x0 … xk terms of the polynomial; lowerBound and upperBound specify the lower and upper bounds of x, i.e., the range of the X-values that will be used for evaluating; and finally percent% indicates when the program should halt – specifically, the program should halt when two successive approximations are within percent percent of one another.
[NOTE: the "%" at the end is required; the value will be expressed as a number with the "%" at the end, i.e., "0.0023%".]

The following additional conditions apply:

  1. You must make program SkateRamp.Java, which can integrate various functions that are built in to your program. Here are some examples of how it might be invoked:

    java SkateRamp poly 1.0 -2.1 3.2 -10.0 +5.0
    [calculates a ramp using the polynomial 1.0 - 2.1x + 3.2x2 from x = -10. to x = 5.0]
    java SkateRamp poly 1.0 -2.1 3.2 -10.0 +5.0 1.0%
    [calculates a ramp using the polynomial 1.0 - 2.1x + 3.2x2 from x = -10. to x = 5.0,
    stopping when successive values are within 1% of each other.]
    java SkateRamp poly 0.0 8.0 -2.0 1.0 4.0 1e-6%
    [calculates a ramp using the polynomial 8x - 2x2 from x = 1.0 to x = 4.0,
    stopping when successive values are within 1*106% of each other.]
    java SkateRamp sin -0.27 +3.55
    [calculates a ramp using the sin function from x = -0.27 to x = +3.55]
    java SkateRamp log 1.1 2.3
    [calculates a ramp using the (natural) log function from x = 1.1 to x = 2.3]
    java SkateRamp exp 2.0 3.5
    [calculates a ramp using the function ex from x = 2.0 to x = 3.5]
    java SkateRamp sqrt 1.0 2.0
    [calculates a ramp using the function sqrt(x) from x = -1.0 to x = 2.0]
  2. In general, the program will be invoked like this:

    java SkateRamp functionName additionalDescriptors

  3. Note that some functions [e.g., polynomials] need the additional descriptors [for their coefficients], while other functions [like sin and sqrt] do not necessarily require them.
  4. If the program is invoked incorrectly, it must output a clear, detailed message that explains precisely how to use it.
  5. You may, if you wish, use a single file for this program; however, there are ample opportunities for using other classes as we've seen in previous assignments. Challenge yourself to find good places to break your code into modules for better separation of concerns.
  6. As always, a comprehensive set of tests should be written before you start coding the other key method(s). In this case you MUST include a method called private static void runMyTests() which will make method calls to a set of test methods. Since you need a main() method to run your program already, you must put the tests in another method. Name that method runMyTests and make your main program check for that on the command line in args[0]. In other words, you MUST be able to run your program using:

    java SkateRamp runMyTests

    and produce appropriate test output like:

    running poly test with 1.0 -2.3 -1.0 3.0 with 0.0001% ~ expected: 123.45, got: 123.45.

  7. Try to implement as many interesting functions as possible, including:
    • polynomials of at least degree 2 [you MUST start with this]
    • polynomials of arbitrary degree [which you may as well do when you have the first part working]
    • the sin function [you MUST implement this as well]
    • other trig functions like cos, tan
    • log and exponentiation functions
    • some composite functions, e.g., sqrt (1 + cos(x) ) or cos(x)cos(2x). Make sure that your lab report clearly explains how these should be invoked.

Notes:

  1. You MUST at a minimum be able to do the polynomial and sin integrations. Start with degree two on the polynomials, then use that as the starting point to get an arbitrary degree.
  2. Once polynomials are working, add on the sin trigonometric function. Then add on some of the others. Don't worry, for these I won't go crazy with composite functions, just the regular ones will do. At a minimum, you MUST get integration of the sin function to work.
  3. Anything else you are able to complete will provide you with one point of extra credit for this assignment. Yes, that means it is possible to get higher than 100% on this project.

Submission Guidelines: Make a sub-directory in your repository as mentioned above, called homework05 and commit your source code into it. DON'T FORGET TO ADD A COMMIT COMMENT!