Lecture 5: In-class Exercise:   Representing Temperature
1 It’s Getting Hot
2 Testing
3 Notes to Keep in Mind
4 To Turn In
7.5

Lecture 5: In-class Exercise: Representing Temperature

Due: Ideally by the end of class, but not later than 24 hours after your section meeting time.

1 It’s Getting Hot

The purpose of this exercise is to give you practice with the new concepts introduced through the Durations example, such as access modifiers, static, and JavaDoc, as well as review concepts such as inheritance, equals/hashCode, and interface polymorphism.

In the starter code, you are given an interface representing a temperature value. Your task is to implement the Temperature interface in two different ways:

You may work freely with other students on this exercise!

You will need two separate classes: a public classed named CelsiusTemperature, and a public class named FahrenheitTemperature. Each class will need two constructors:

All implementations should override equals(), hashCode(), and toString(). The toString() method should return a String as follows: "NN.N° Fahrenheit", namely, the temperature to one decimal place precision followed by the degree symbol and Fahrenheit, e.g., "30.1° Fahrenheit", for the FahrenheitTemperature class, and similarly for the CelsiusTemperature class but substituting "Celsius" for "Fahrenheit". You may want to copy and paste the degree symbol (°) from this Web page into IntelliJ. You may find it useful to use String.format("%.1f") to convert a double to a String with one decimal place.

The formulas for converting between Celsius and Fahrenheit are as follows:

From Celsius to Fahrenheit, C * 9/5 + 32 From Fahrenheit to Celsius, (F - 32) * 5/9

2 Testing

We have supplied you with some basic JUnit tests as part of the starter code. Use these to verify that your implementation is correct, and write additional tests of your own.

3 Notes to Keep in Mind

4 To Turn In

Submit your zip containing only your src and test directories to In-class Exercise 1 on the handin server. There is no self-evalulation for this exercise.