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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started