Calculator.java
上传用户:hensond
上传日期:2021-12-27
资源大小:817k
文件大小:1k
- package com.company.section6;
- /**
- * @author cbf4Life cbf4life@126.com
- * I'm glad to share my knowledge with you all.
- */
- public enum Calculator {
- //加法运算
- ADD("+"){
- public int exec(int a,int b){
- return a+b;
- }
- },
- //减法运算
- SUB("-"){
- public int exec(int a,int b){
- return a - b;
- }
- };
-
- String value = "";
- //定义成员值类型
- private Calculator(String _value){
- this.value = _value;
- }
- //获得枚举成员的值
- public String getValue(){
- return this.value;
- }
-
- //声明一个抽象函数
- public abstract int exec(int a,int b);
- }