Class TemperatureConversion

java.lang.Object
  |
  +--TemperatureConversion

public class TemperatureConversion
extends java.lang.Object

The TemperatureConversion Java application prints a table converting Celsius to Fahrenheit degrees.

Author:
Michael Main (main@colorado.edu)
See Also:
Java Source Code (www.cs.colorado.edu/~main/applications/TemperatureConversion.java)

Constructor Summary
TemperatureConversion()
           
 
Method Summary
static double celsiusToFahrenheit(double c)
          Convert a temperature from Celsius degrees to Fahrenheit degrees.
static void main(java.lang.String[] args)
          The main method prints a Celsius to Fahrenheit conversion table.
static void printNumber(double d, int minimumWidth, int fractionDigits)
          Print a number to System.out, using a specified format.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TemperatureConversion

public TemperatureConversion()
Method Detail

main

public static void main(java.lang.String[] args)
The main method prints a Celsius to Fahrenheit conversion table. The bounds of the table range from -50C to +50C in 10 degree increments. The String argumments (args) are not used in this implementation.


celsiusToFahrenheit

public static double celsiusToFahrenheit(double c)
Convert a temperature from Celsius degrees to Fahrenheit degrees.

Parameters:
c - a temperature in Celsius degrees
Precondition:
c >= -273.16.
Returns:
the temperature c converted to Fahrenheit
Throws:
java.lang.IllegalArgumentException - Indicates that c is less than the smallest Celsius temperature (-273.16).

printNumber

public static void printNumber(double d,
                               int minimumWidth,
                               int fractionDigits)
Print a number to System.out, using a specified format.

Parameters:
d - the number to be printed
minimumWidth - the minimum number of characters in the entire output
fractionDigits - the number of digits to print on the right side of the decimal point
Precondition:
fractionDigits is not negative.
Postcondition:
The number d has been printed to System.out. This printed number is rounded to the specified number of digits on the right of the decimal. If fractionDigits is 0, then only the integer part of d is printed. If necessary, spaces appear at the front of the number to raise the total number of printed characters to the minimum. Additional formatting details are obtained from the current locale. For example, in the United States, a period is used for the decimal and commas are used to separate groups of integer digits.
Throws:
java.lang.IllegalArgumentException - Indicates that fractionDigits is negative.
Example:
printNumber(12345.27, 8, 1); // Prints 12,345.3 in the U.S.