Олимпиадный тренинг

Задача . 37351


Задача

Темы:

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.
}

The formula to convert degrees Celsius C to Fahrenheit F is
                             F = 1.8C + 32
For example, 30? C is equivalent to 86? F.
An inFahrenheit() accessor method is added to the Temperature class. Here is its implementation:

/** Precondition: The temperature is a valid temperature
* in degrees Celsius.
* Postcondition:
* - An equivalent temperature in degrees Fahrenheit has been
* returned.
* - Original temperature remains unchanged.
* @return an equivalent temperature in degrees Fahrenheit
*/
public Temperature inFahrenheit()
{
 Temperature result;
 /* more code */
 return result;
}


Which of the following correctly replaces /* more code */ so that the postcondition is achieved?

I result = new Temperature(degrees * 1.8 + 32, "F");
II result = new Temperature(degrees * 1.8, "F");
   result = result.raise(32);
III degrees *= 1.8;
    this = this.raise(32);
    result = new Temperature(degrees, "F");

(A) I only
(B) II only
(C) III only
(D) I and II only
(E) I, II, and III

time 1000 ms
memory 32 Mb
Правила оформления программ и список ошибок при автоматической проверке задач

Статистика успешных решений по компиляторам
Комментарий учителя