CS56—Midterm Exam 1—Question 1
E01, Q01, W12, Phill Conrad, UC Santa Barbara 02/07/2012

STAPLE YOUR NOTES SHEET TO THIS ONE, AND HAND IT IN WITH YOUR EXAM.
YOU MAY USE THIS FOR SCRATCH WORK, BUT ALL ANSWERS SHOULD BE ON YOUR EXAM PAPER.

Name:
___________________________________________________


Umail Address: ______________________________@ umail.ucsb.edu

  1. Write the code for the TideReading class, per the instructions below.


    A tide reading object represents:
    • a tide type, which is a single character, either L for low or H for high.
    • a tide level, which is a real number. Typical values range from -2.0 to 6.0.

    Please note that it is NOT the case that positive level values always correspond to high tides, and not all low tides have negative values.
    So it is necessary to keep both pieces of data.

    For full credit, your class should have all of the following.
    Go over this as a "checklist" when you are finished to make sure you have everything needed.

    1. (10 pts) Correct syntax and structure of a Java class.

    2. (4 pts) A Javadoc comment for the ENTIRE class. DO NOT USE YOUR REAL NAME.
      Use "Shane Botwin" for the @author, and "CS56 Midterm 1" for the @version.

    3. (10 pts) A two-argument constructor that takes arguments for type,level. (Leave room for a Javadoc comment)
      Example invocation: TideLevel a = new TideReading('H',3.4);

    4. (4 pts) Private instance variables for the tide type, and the tide level.

    5. (4 pts) Add a Javadoc comment for the two argument constructor with @param tags for the parameters.

      TO SAVE TIME, YOU DO NOT NEED ANY MORE JAVADOC COMMENTS ON THIS PROBLEM.

    6. (6 pts) getter methods called getType() and getLevel(). Do not create setters, only getters.

    7. (6 pts) a correct toString() method. Examples of the string value that should be returned: "Low (-2.0)" or "High (6.0)".

      Hint: You may use the static method of the String class, String.format("%.1f",variable) to convert a double value to a string representation with 1 decimal place.

    8. (6 pts) a correct equals() method. Two tides should be considered equal if they have the same type, and—read this carefully!—their tide level would print the same when converted to a string formatted to one decimal place. (Think carefully about the easiest way to implement this!)

      As a reminder: the first three lines of every correct equals() method check for null, check the type, and cast the parameter to an instance of the type of the current object. You may copy the following into your method as the first three "boiler plate" lines of code—just write the line(s) that come after these.

      If you want, to save time, just put a comment: // boiler plate here at the start of your equals method, and I'll know that you want those three lines copied in your answer at that point.

      // boiler-plate for an equals method:
      if (o==null) {return false};
      if (! (o instanceof TideReading) ) {return false;}
      TideReading tr = (TideReading) o;       

End of Q01 HandoutTotal points: ?