开发者

how would you implement an interface in java example calculator [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
开发者_C百科

Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist

Closed 9 years ago.

Improve this question

I've got a Calculator interface that contains

public interface Calculator {

    public void setOperator(char operator);         
    public void setOperand (double operand);  
    public double getResult();
}

How would i implement this in another class, for a basic calculator???


Create a class that implements the Calculator interface and implement all the methods as desired.

public class CalculatorImpl implements Calculator {
    public void setOperator(char operator) {
        throw new UnsupportedOperationException("implement me.");
    }         
    public void setOperand (double operand) {
        throw new UnsupportedOperationException("implement me.");
    }  
    public double getResult() {
        throw new UnsupportedOperationException("implement me.");
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜