CS 214
Project 9: Abstract Data Types
This week's exercise is to create a full-featured Temperature
type. Such a type has the following attributes:
-
degrees, a real value; and
-
scale, a (single) character value
(one of 'F', 'C', 'K'
'f', 'c', or 'k').
You are to build such a type in each of our four languages:
Java, Ada, Clojure, and Ruby.
Your type should take full advantage of the modularity features available
in each language, as presented in this week's lab exercise.
Warning: This project is much longer than others have been.
Begin immediately!
Details.
Your Temperature type must provide the following operations:
-
Inititalization to a given degrees and scale.
This operation must validate the given values, to ensure that
they constitute a valid temperature.
-
Accessor operations to retrieve the degrees and scale
attributes.
-
Converter operations:
-
An operation that, given an arbitrary Temperature,
returns the equivalent Temperature in Fahrenheit.
-
An operation that, given an arbitrary Temperature,
returns the equivalent Temperature in Celsius.
-
An operation that, given an arbitrary Temperature,
returns the equivalent Temperature in Kelvin.
-
I/O Operations:
-
An input operation that lets a Temperature be conveniently input
as a single entity (e.g., 98.6 F).
This method should validate the input values and display
an error diagnostic if they do not constitute a valid temperature.
-
An output operation that lets a Temperature be displayed
conveniently.
-
Adjustment operations:
-
A raise() operation that,
given a Temperature and real degrees,
returns a Temperature that is degrees higher than
the Temperature received.
-
A lower() operation that,
given a Temperature and a real degrees,
returns a Temperature that is degrees lower than
the Temperature received.
This operation must validate the resulting temperature,
to ensure that it is a valid temperature.
-
Relational operations:
-
equals that, given two Temperature operands,
returns true if and only if the left operand is equal to
the right operand.
(Note: Two temperatures need not have the same scale to be equal.)
-
less-than that, given two Temperature operands,
returns true if and only if the left operand is less-than
the right operand.
(Note: This operation should work correctly regardless of
the operands' scales.)
Hint: To avoid redundant coding effort,
write a utility method that, given a real value and a character value,
returns true if and only if they constitute a valid temperature.
Testing.
For each language, show that your Temperature type and its
operations work correctly by writing a program that prints a
temperature table.
Your program should satisfy the following specification:
-
Input:
-
baseTemp, a Temperature;
-
limitTemp, a Temperature; and
-
stepValue, a real.
-
Output:
-
A nicely formatted table of Fahrenheit, Celsius, and Kelvin temperature values,
beginning with baseTemp
and incrementing by stepValue in the scale of the baseTemp,
without exceeding limitTemp.
Turn in.
Using an approach like what we did in the lab, make a single script file named
proj09-results, in which you list each program,
show that it builds without any syntax errors or warnings,
and show same executions that demonstrate its correctness.
cat java-script ada-script clojure-script ruby-script > proj09-script
Each language's script file should show the code you write in that language,
the program building correctly,
and the program executing using these input values:
0 F
100 C
2.5
and
0 K
212 F
20.0
Then submit your project by copying that single file
into your personal folder in /home/cs/214/current/:
cp proj09-results /home/cs/214/current/yourUserName
replacing yourUserName with your login name.
The grader will access and grade your project results from there,
using the criteria from
this grade sheet.
Calvin >
CS >
214 >
Projects >
09
This page maintained by
Joel Adams.