CMPS 134 Fall 2019
Programming Assignment #2: Temperature Table
Due: 11:59pm, Wednesday, September 18

Historically, several different scales have been developed and used to quantify temperatures. Celsius and Fahrenheit may be the best known, but there are others. Relevant conversion formulae may be found in Wikipedia's Conversion_of_units_of_temperature article.

For this assignment you are given the Java program TemperaturesI01, which you are to incrementally modify and extend so it behaves as exemplified in the following user-program dialog.2.

This is the Temperatures program.
Enter the start value >:0
Enter the stop value >:100
Enter the increment >:20
      C ||      F |      K |      R |     De |      N |     Re |     Ro |
--------++--------+--------+--------+--------+--------+--------+--------+
   0.00 ||  32.00 | 273.15 | 491.67 | 150.00 |   0.00 |   0.00 |   7.50 |
  20.00 ||  68.00 | 293.15 | 527.67 | 120.00 |   6.60 |  16.00 |  18.00 |
  40.00 || 104.00 | 313.15 | 563.67 |  90.00 |  13.20 |  32.00 |  28.50 |
  60.00 || 140.00 | 333.15 | 599.67 |  60.00 |  19.80 |  48.00 |  39.00 |
  80.00 || 176.00 | 353.15 | 635.67 |  30.00 |  26.40 |  64.00 |  49.50 |
 100.00 || 212.00 | 373.15 | 671.67 |   0.00 |  33.00 |  80.00 |  60.00 |
--------++--------+--------+--------+--------+--------+--------+--------+

Note that this program prompts for and accepts input values that define a range of Celsius temperatures, which are then used to produce a formatted table showing the corresponding temperature values on the Fahrenheit, Kelvin, Rankine, Delisle, Newton, Réaumur and Rømer scales. Consider the following as a second example.

This is the Temperatures program.
Enter the start value >:-100
Enter the stop value >:200
Enter the increment >:50
      C ||      F |      K |      R |     De |      N |     Re |     Ro |
--------++--------+--------+--------+--------+--------+--------+--------+
-100.00 ||-148.00 | 173.15 | 311.67 | 300.00 | -33.00 | -80.00 | -45.00 |
 -50.00 || -58.00 | 223.15 | 401.67 | 225.00 | -16.50 | -40.00 | -18.75 |
   0.00 ||  32.00 | 273.15 | 491.67 | 150.00 |   0.00 |   0.00 |   7.50 |
  50.00 || 122.00 | 323.15 | 581.67 |  75.00 |  16.50 |  40.00 |  33.75 |
 100.00 || 212.00 | 373.15 | 671.67 |   0.00 |  33.00 |  80.00 |  60.00 |
 150.00 || 302.00 | 423.15 | 761.67 | -75.00 |  49.50 | 120.00 |  86.25 |
 200.00 || 392.00 | 473.15 | 851.67 |-150.00 |  66.00 | 160.00 | 112.50 |
--------++--------+--------+--------+--------+--------+--------+--------+

The given TemperaturesI0 program, as you can verify by running it, essentially just echoes a single input value. Here is an example user-program dialog:

This is the TemperaturesI0 program.
Enter a Celsius value >:50.0
50.0 ||

In the spirit of "Incremental Development" (aka "Iterative Enhancement" in Chapter 1 of our text), you are to develop and submit a series of intermediate versions of this program as illustrated by the following user-program dialogs.

In the first increment, I1, the conversion formulae for the various temperature scales have been incorporated and these results printed in sequence on the same line as the inputted Celsius value, separated by vertical bars:

This is the TemperaturesI1 program.
Enter a Celsius value >:100.0
100.0 ||212.0 |373.15 |671.67 |0.0 |33.0 |80.0 |60.0 |

In the second increment, I2, the user is prompted to input values that define the interval over which the conversions are to be employed, and a for loop is used to iterate over the interval using the specified increment:

This is the TemperaturesI2 program.
Enter the start value >:0
Enter the stop value >:100
Enter the increment >:17
0.0 ||32.0 |273.15 |491.66999999999996 |150.0 |0.0 |0.0 |7.5 |
17.0 ||62.6 |290.15 |522.27 |124.5 |5.61 |13.6 |16.425 |
34.0 ||93.2 |307.15 |552.87 |99.0 |11.22 |27.2 |25.35 |
51.0 ||123.8 |324.15 |583.47 |73.5 |16.83 |40.8 |34.275 |
68.0 ||154.4 |341.15 |614.0699999999999 |48.0 |22.44 |54.4 |43.2 |
85.0 ||185.0 |358.15 |644.67 |22.5 |28.05 |68.0 |52.125 |

In the third increment, I3, a properly aligned header is printed and the following method, printReal() (rather than the standard method, System.out.print()), is used to align the values in each cell so as to improve the readability of the output.3 (That is, in place of using System.out.print(x) to print the value of x (of type double), use printReal(x) instead.)

/* Parameterized method that prints the given real number, 
** right justified, using exactly seven character positions, with 
** two of those positions to the right of the decimal point.
*/
public static void printReal(double realNum) {
   System.out.printf("%7.2f",realNum);
}

This is the TemperaturesI3 program.
Enter the start value >:0
Enter the stop value >:100
Enter the increment >:20
      C ||      F |      K |      R |     De |      N |     Re |     Ro |
   0.00 ||  32.00 | 273.15 | 491.67 | 150.00 |   0.00 |   0.00 |   7.50 |
  20.00 ||  68.00 | 293.15 | 527.67 | 120.00 |   6.60 |  16.00 |  18.00 |
  40.00 || 104.00 | 313.15 | 563.67 |  90.00 |  13.20 |  32.00 |  28.50 |
  60.00 || 140.00 | 333.15 | 599.67 |  60.00 |  19.80 |  48.00 |  39.00 |
  80.00 || 176.00 | 353.15 | 635.67 |  30.00 |  26.40 |  64.00 |  49.50 |
 100.00 || 212.00 | 373.15 | 671.67 |   0.00 |  33.00 |  80.00 |  60.00 |

The final increment, Temperatures, augments the output with horizontal bars that bound the body of the table. (See the first two user-program dialogs on this page.)


Submitting Your Source Code

You are to submit four Java source code files: TemperaturesI1.java, TemperaturesI2.java, TemperaturesI3.java, and Temperatures.java. (We omit I4 from the last program's name because it is a "finished" program satisfying our original goals.)

Follow the same procedure as you did for the previous assignment, except that you should submit to the "prog2_dir" folder. It is recommended that, after you submit a file, you should then try to retrieve it. If what you get back is different than what you (thought you had) submitted, something went wrong and you should try to submit again.

Note that, with respect to any given increment, if you make corrections or improvements to it, you can submit it a second (or third, etc.) time. Your file's name should be the same each time! Within the submission folder, any file having that name will be renamed automatically (and still be accessible to both you and your instructor). Generally speaking, however, your instructor will probably examine only your most recent submission, unless you make a request to the contrary.

Make sure to include comments in your programs that identify yourself, indicate that it is a solution to CMPS 134's Prog. Assg. #2, acknowledge any persons who aided you in developing your solution, and point out any flaws of which you are aware. (These comments should be placed just above the class heading; use this as a template.)


Footnote

[1] The last character in "TemperaturesI0" is zero, not the similar-looking letter.

[2] In the user-program dialogs, input entered by the user is shown in boldface.

[3] As you can see, the printReal() method calls System.out.printf(). Links to programs showing more examples of using printf() can be found on the course web page, under Programming Samples: Relevant to Chapter 3.