public class Temperature
{
private String scale; //valid values are "F" or "C"
private double degrees;
/** constructor with specified degrees and scale */
public Temperature(double tempDegrees, String tempScale)
{ /* implementation not shown */ }
/** Mutator. Converts this Temperature to degrees Fahrenheit.
* Precondition: Temperature is a valid temperature
* in degrees Celsius.
* @return this temperature in degrees Fahrenheit
*/
public Temperature toFahrenheit()
{ /* implementation not shown */ }
/** Mutator. Converts this Temperature to degrees Celsius.
* Precondition: Temperature is a valid temperature
* in degrees Fahrenheit.
* @return this temperature in degrees Celsius
*/
public Temperature toCelsius()
{ /* implementation not shown */ }
/** Mutator.
* @param amt the number of degrees to raise this temperature
* @return this temperature raised by amt degrees
*/
public Temperature raise(double amt)
{ /* implementation not shown */ }
/** Mutator.
* @param amt the number of degrees to lower this temperature
* @return this temperature lowered by amt degrees
*/
public Temperature lower(double amt)
{ /* implementation not shown */ }
/** @param tempDegrees the number of degrees
* @param tempScale the temperature scale
* @return true if tempDegrees is a valid temperature
* in the given temperature scale, false otherwise
*/
public static boolean isValidTemp(double tempDegrees,
String tempScale)
{ /* implementation not shown */ }
//Other methods are not shown.
}
Consider the following code:
public class TempTest
{
public static void main(String[] args)
{
System.out.println("Enter temperature scale: ");
String tempScale = IO.readString(); //read user input
System.out.println("Enter number of degrees: ");
double tempDegrees = IO.readDouble(); //read user input
/* code to construct a valid temperature from user input */
}
}
Which is a correct replacement for /* code to construct. . . */?
I Temperature t = new Temperature(tempDegrees, tempScale);
if (!t.isValidTemp(tempDegrees,tempScale))
/*
error message and exit program */
II if (isValidTemp(tempDegrees,tempScale))
Temperature t = new Temperature(tempDegrees, tempScale);
else
/*
error message and exit program */
III if (Temperature.isValidTemp(tempDegrees,tempScale))
Temperature t = new Temperature(tempDegrees, tempScale);
else
/*
error message and exit program */
(A) I only
(B) II only
(C) III only
(D) I and II only
(E) I and III only