CIS 180: Object-Oriented Programming
Programming Project #1

The Temperature Class

Due by September 30, 2003

Objectives

The objectives of this homework are:

Problem Statement

Design and implement a class for a Temperature object that is capable of reporting its temperature in either Fahrenheit or Celsius. This class should have one instance variable called degrees, which contains the Fahrenheit temperature, and two public methods, one called getFahrenheit(), which returns the temperature in Fahrenheit, and one called getCelsius(), which returns the temperature in Celsius. This method has to convert the stored temperature to Celsius before returning it. An expression for converting Fahrenheit to Celsius is (5 *(F -32) /9), where F is the temperature in Fahrenheit.

Test your class definition by implementing a main() method that creates Temperature instances and displays their temperature values.

Your program should produce something like the following output in the Java console:

 The Fahrenheit temperature of thermometer1 is 20.0 degrees.
The Celsius temperature of thermometer1 is -6.67 degrees.
 The Fahrenheit temperature of thermometer2 is 98.6 degrees.
The Celsius temperatureof thermometer2 is 37.0 degrees.

Problem Decomposition

This problem can be divided into one class, the Temperature class, which will implement the temperature conversion. It will contain a main() method in which Temperature instances will be created and used.

Design

Implementation

Optional

If time and energy permits, you may want to try this optional exercise, which makes use of Java's input class, BufferedReader.

What to turn in

When your assignment is complete, add some comments to the beginning of the java source code explaining any problems you encountered in completing the assignment and describing any bugs in your solution. Undocumented bugs are worse than documented bugs. If you have undocumented bugs we will assume that you did an inadequate job of testing your code, and you will lose additional points.

To submit your homework, follow the link from the homework page to the homework submission form.

There will be a 10% penalty for assignments received after the due date. Assignments will not be accepted more than one week past the due date.


You're done. Great work!