001package enumeration; 002 003public abstract class Op { 004 private final String name; 005 Op(String name) { this.name = name; } 006 public String toString() { return name; } 007 008 public abstract int eval(int x, int y); 009 010 public static final Op ADD = new OpAdd(); 011 public static final Op SUB = new OpSub(); 012 public static final Op MUL = new OpMul(); 013 public static final Op DIV = new OpDiv(); 014} 015 016final class OpAdd extends Op { 017 OpAdd() { super("+"); } 018 public int eval(int x, int y) { return x+y; } 019} 020final class OpSub extends Op { 021 OpSub() { super("-"); } 022 public int eval(int x, int y) { return x-y; } 023} 024final class OpMul extends Op { 025 OpMul() { super("*"); } 026 public int eval(int x, int y) { return x*y; } 027} 028final class OpDiv extends Op { 029 OpDiv() { super("/"); } 030 public int eval(int x, int y) { return x/y; } 031}