이 줄의 작동 방식을 알려주십시오 .... 내 OperatorFactory.get ("add")는 아무 것도하지 않습니다. 나는 다음과 같은 때 아무것도 자바 인터페이스 ... 빠른 질문
ArithmeticOperator add = OperatorFactory.get ("add");
인쇄받지 못했습니다 :
interface ArithmeticOperator {
// Returns the result of applying the operator to operands a and b.
double operate (double a, double b);
// Return a String that is the name of this operator.
String printName();
}
public class OperatorFactory implements ArithmeticOperator {
public OperatorFactory(){
}
public static ArithmeticOperator get(String name){
if(name.equals("add"))
return new PlusOperator();
else if(name.equals("sub"))
return new SubOperator();
else if(name.equals("mult"))
return new MultOperator();
else if(name.equals("div"))
return new DivOperator();
else
return null;
}
public double operate(double a, double b) {
throw new UnsupportedOperationException("Not supported yet.");
}
public String printName() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
public class PlusOperator extends OperatorFactory {
public double operate(double a, double b) {
return a + b;
}
public String printName() {
return "Add";
}
}
public class PlusOperator extends OperatorFactory {
public double operate(double a, double b) {
return a + b;
}
public String printName() {
return "Add";
}
}
왜 인쇄를해야합니까? ** printName() ** 메서드를 호출하지 않고 그냥 구현하고 있습니다. – Jack
"나는 아무것도 인쇄하지 않습니다." 글쎄, 코드는 어디서나 그것을하지 않습니다. 어디/어떻게 당신이 무언가를 인쇄하고 있습니까? – BalusC
"나는 아무것도 인쇄하지 않습니다."- 어디에서 무엇을 인쇄하려고합니까? 여기 코드에 보이지 않습니다 –