Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Enum type with constant-specific class bodies and data
- public enum Operation {
- PLUS("+") {
- double apply(double x, double y) { return x + y; }
- },
- MINUS("-") {
- double apply(double x, double y) { return x - y; }
- },
- TIMES("*") {
- double apply(double x, double y) { return x * y; }
- },
- DIVIDE("/") {
- double apply(double x, double y) { return x / y; }
- };
- private final String symbol;
- Operation(String symbol) { this.symbol = symbol; }
- @Override public String toString() { return symbol; }
- abstract double apply(double x, double y);
- }
Advertisement
Add Comment
Please, Sign In to add comment