COMS S1004

Homework #2

Due 5:30pm Mon Jun 8

Theory

Do the following questions from Schneider & Gersting Third Edition:
Chapter 3: 10, 11, 19, 25, 28
PLEASE NOTE!!! For question 10, the first sentence should be "... are performed on a list of six elements that is already sorted in the reverse order".

Programming

In this assignment, you will create a program that can represent, solve, and evaluate quadratic equations of the form: y = ax2 + bx + c.

First, create a class called QuadraticEquation. It should have three attributes to hold the values of a, b, and c; these should have appropriate accessor methods. It should also have a constructor that allows for the initialization of these values. And it should have a method "evaluate" which takes as its input the value of x and returns the value of the quadratic formula.

Next, create a class called QuadraticEquationSolver. This class should have a QuadraticEquation as one of its attributes; this should be set via a parameter to the constructor, but you should also have a mutator method to set this attribute, too. The class should also have attributes "solution1" and "solution2" (remember, a quadratic equation can have two solutions) and corresponding accessor methods. Last, create a method called "solve" that solves the quadratic equation ax2 + bx + c = 0. The method should set the values of "solution1" and "solution2" appropriately.

NOTE: you may assume that the values of a, b, and c are such that a real solution can be calculated. Just be sure to choose a sufficiently big value of b when you do your testing. If you try to take the square root of a negative number, the program may crash or produce unexpected results; that's okay at this point, but we'll see how to deal with that soon.

Last, create a class called QuadraticEquationTest that prompts the user to enter values for a, b, and c and then creates a QuadraticEquation. It should then ask the user for a value of x, evaluate the formula, and print out the result. Then it should use the QuadraticEquationSolver to find the equation's (real) solutions and print those out to the screen.

HINT: You should be using Scanner and System.out.println only in the QuadraticEquationTest class, and not in the other two. Try to separate the "concept" of a quadratic equation and its solver from the "user interface" of a program that uses those classes.

Please be sure to include a "README" file with your submission. For this assignment, it should be about two paragraphs long. You should explain how your program works, how to run it, what the output means, and how you performed all of the calculations.

Grading
The Theory part is worth 50 points total. Each question is worth 10 points.

The Programming part is worth a total of 50 points, distributed as follows:

  • Your program must compile with no errors (5 points)
  • Your program must implement the classes and the corresponding methods described above (5 points)
  • The program should produce the correct results for evaluating and solving the quadratic equation, assuming that real solutions exist (30 points)
  • Your program should include a README file, be well-commented, use good variable names, be easy to read, etc. (10 points)

  • Submitting your assignment

    For the Theory assignment, print a paper copy and submit it at the beginning of class. You do not need to submit it electronically.

    For the Programming assignment, submit a paper copy of all your source code and submit it electronically by the due date. Put all your .java files and your README file in a .zip or .tar file, then follow these instructions:

    1. Make sure the zip/tar file name clearly indicates your UNI and the name of the assignment, e.g. xyz1234-hwk2.zip
    2. Log onto CourseWorks and go to the page for COMS S1004
    3. Click on CLASS FILES in the left hand side menu
    4. Click on POST FILE in the top menu, and fill the form to submit your zip/tar file
    5. Make sure you choose Homework #2 (under "Shared Files") as the "Post file To" destination (the contents of this folder should only be visible to the teaching staff)
    6. Click the "Submit" button
    7. All done! (Laugh maniacally)

    Remember, only submit your .java files and the README file, not the .class files. If you're using Eclipse, you can find the location of the .java files by right-clicking on the Java project and selecting "Properties...". Then in the Resources window you'll see "Location". That's the location of the project. The .java files should be in the folder called "src".