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

Задача . 26


Задача

Темы:
Consider the Orderable interface and the partial implementation of the Temperature class defined below:

    public interface Orderable
    {
        /** Returns -1, 0, or 1 depending on whether the implicit
        * object is less than, equal to, or greater than other.
*/
        int compareTo(Object other);
    }
    public class Temperature implements Orderable
    {
    private String scale;
    private double degrees;
    //default constructor
    public Temperature()
    { /* implementation not shown */ }
    //constructor
    public Temperature(String tempScale, double tempDegrees)
    { /* implementation not shown */ }
    public int compareTo(Object obj)
    { /* implementation not shown */ }
    public String toString()
    { /* implementation not shown */ }
    //Other methods are not shown.
}

Here is a program that finds the lowest of three temperatures:

    public class TemperatureMain
    {
        /** Find smaller of objects a and b. */
        public static Orderable min(Orderable a, Orderable b)
        {
            if (a.compareTo(b) < 0)
                return a;
            else
                return b;
        }
        /** Find smallest of objects a, b, and c. */
        public static Orderable minThree(Orderable a,
        Orderable b, Orderable c)
        {
            return min(min(a, b), c);
        }
        public static void main(String[] args)
        {
            /* code to test minThree method */
        }
    }

Which are correct replacements for /* code to test minThree method */?
I) Temperature t1 = new Temperature("C", 85);
Temperature t2 = new Temperature("F", 45);
Temperature t3 = new Temperature("F", 120);
System.out.println("The lowest temperature is " + minThree(t1, t2, t3));

II) Orderable c1 = new Temperature("C", 85);
Orderable c2 = new Temperature("F", 45);
Orderable c3 = new Temperature("F", 120);
System.out.println("The lowest temperature is " + minThree(c1, c2, c3));

III) Orderable c1 = new Orderable("C", 85);
Orderable c2 = new Orderable("F", 45);
Orderable c3 = new Orderable("F", 120);
System.out.println("The lowest temperature is " + minThree(c1, c2, c3));

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

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

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