?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Difficult

Public Class CrazyArithmetic

APCSA-YYLVB4

Consider the following class.

public class CrazyArithmetic 
{
    private String answer;

    public CrazyArithmetic(int a, int b, String operator)
    {
        if (operator.equals("/"))
            answer = ((double)a/b)+"";
        else
        if (operator.equals("*&"))
            answer = (a*b)+"";
        else
        if (operator.equals("-"))
            answer = (a-b)+"";
        else
        if (operator.equals("+"))
            answer = (double)(a+b)+"";
    }

    public CrazyArithmetic(double a, double b, String operator)
    {
        if (operator.equals("/"))
            answer = ((int)a/(int)b)+"";
        else
        if (operator.equals("*"))
            answer = (a*b)+"";
        else
        if (operator.equals("-"))
            answer = (a-b)+"";
        else
        if (operator.equals("+"))
            answer = (int)(a+b)+"";
    }

    public CrazyArithmetic(double a, int b, String operator)
    {
        answer = new CrazyArithmetic(a,(double)b,operator).getAnswer();
    }

    public CrazyArithmetic(int a, double b, String operator)
    {
        answer = new CrazyArithmetic(a,(int)b,operator).getAnswer();
    }

    public String getAnswer()
    {
        return answer;
    }

}

Which of the following statements would execute without throwing an error?

I.   CrazyArithmetic c1 = new CrazyArithmetic(5.0, 10.0, "add");
II.  CrazyArithmetic c2 = new CrazyArithmetic(20.0, 8, "/");
III. CrazyArithmetic c3 = new CrazyArithmetic(2, 4, "/");
A

III only.

B

I and II only.

C

II and III only.

D

I and III only.

E

I, II, and III.