Comp 110
Lab Project #11
Due: 3/18/2006
Write a
Temperature class that has two parameters: a temperature value (a
floating-point number) and a character for the scale, either C for Celsius or
F for Fahrenheit. The class should
have four constructor methods: one for each instance variable (assume zero
degrees if no value is specified and Celsius if no scale is specified), one
with two parameters for the two instance variables, and a default constructor
(set to zero degrees Celsius). Include
(1) two accessor methods to return the temperature, one to return the degrees
Celsius, the other to return the degrees Fahrenheit use the formulas from
Programming Project 2 of Chapter 3 to write the two methods, and round to the
nearest tenth of a degree; (2) three set methods, one to set the value, one to
set the scale (F or C), and one to set both; and (3) comparison methods,
one to test whether two temperatures are equal, one to test whether one
temperature is greater than another, and one to test whether one temperature is
less than another. Then write a driver
program that tests all the methods. Be
sure to use each of the constructors, to include at least one true and one
false case for each comparison method, and to test at least the following
temperature equalities: 0.0 degrees C = 32.0 degrees F, -40.0 degrees C = -40.0
F, and 100.0 degrees C = 212.0 degrees F.
(See problem 7 on page 413 of the text)
Create a
UML Class diagram showing all the instance variables and methods required.
For each
method of the class write a description of what it does. That is, write what would be appropriate to
put in comments in the front of the method to serve as the user interface to
the method. Be sure to describe all the
input and output parameters, if any, for each method. For each method that calculates something
give the equation(s) or, for complicated methods, provide pseudo instructions
(pseudocode) showing the steps of each such method.
Make sure
your all your code is self-documented including an appropriate comment header
block for each class. Use indentation to
make the structure of your code clear.
Test you
code by running a sufficient number of test cases.
Turn in
your design along with the code and the results from running the test cases.
You dont have
to do this all by yourself. You may
partner with someone else in the class to complete this assignment.