CSCI 241 Labs: PreLab 11

CSCI 241 Labs: PreLab 11
Concepts in Object-Oriented Design


Introduction

Chapter 9 of our text introduces you to making your own classes and objects in Java. These include: The syntax behind these features is the easy part. Learning how and when to use them is more difficult, and to a certain extent, will only come with much practice. This prelab will walk you through the design of a Thermometer class that uses many of these features.

Temperature

There are multiple different temperature scales used for different purposes. Most of us in the United States are still more comfortable using the Fahrenheit scale than any other. In Fahrenheit water freezes at 32 degrees and boils at 212 degrees. Most of the rest of the world uses the Celsius scale. In Celsius water freezes at 0 degrees and boils at 100 degrees. There is also the strange concept of absolute zero. Absolute zero is the coldest possible temperature in the entire universe. It is -273.15 degrees Celsius and -459.67 degree Fahrenheit. Remember that the next time the temperature outside reaches 30 below!


Some baseline temperatures in the two scales:

temperature degrees Celsiusdegrees Fahrenheit
symbol °C°F
boiling point of water100.0212.0
freezing / melting point of water / ice0.032.0
absolute zero-273.15-459.67


Temperature conversions

There are simple mathematical formulas we can use to convert a temperature in one scale to the other:

 

Designing a Thermometer Class

When we design an instantiable class, the two basic questions we ask should be:
What kind of data do we want in our objects? and
Which methods do we want in our objects?
We also need to determine if we wish to include static data and methods in our classes.

Let's consider designing a Thermometer class.

 

Something to Think About

Many modern thermometers also keep track of maximum and minimum temperatures. We already have all the coding skills we need to make our thermometers do this. What additional data members and methods would you add to the class so that thermometer objects will know their max and min temperatures?