开发者

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

开发者 https://www.devze.com 2023-02-18 16:03 出处:网络
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
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

精彩评论

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