Question: 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

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, "/");

Select one answer

A III only.

B I and II only.

C II and III only.

D I and III only.

E I, II, and III.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!