?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Difficult

Crazy Arithmetic: Classes

APCSA-TKPEGL

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

    }

What is output to the console from this segment of code from the main method?

CrazyArithmetic ca1 = new CrazyArithmetic(5.0, 10.0, "/");
CrazyArithmetic ca2 = new CrazyArithmetic(4, 5, "+");
CrazyArithmetic ca3 = new CrazyArithmetic(10.0, 4, "/");
CrazyArithmetic ca4 = new CrazyArithmetic(8, 7.0, "+");
CrazyArithmetic ca5 = new CrazyArithmetic(5, 10, "/");
System.out.println(ca1.getAnswer() + ", " + ca2.getAnswer() +
        ", " + ca3.getAnswer() + ", " + ca4.getAnswer() + ", " + ca5.getAnswer());
A

0, 9.0, 2, 15.0, 0.5

B

0.5, 9, 2.5, 15.0, 0

C

0, 9.0, null, null, 0.5

D

0.5, 9.0, 2.5, 15.0, 0.0

E

The result is a constructor method not found syntax error.