Guest User

Amplifier.java

a guest
Dec 30th, 2012
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. package com.gmail.lopezitospriter.Weed;
  2.  
  3. public enum Amplifier {
  4.     plus, minus, times, divide, equals;
  5.  
  6.     public int getResult(int value, int arg, int max) {
  7.         int i = getResult(value, arg);
  8.  
  9.         if (i > max)
  10.             return max;
  11.         return i;
  12.     }
  13.  
  14.     public int getResult(int value, int arg) {
  15.         switch (this) {
  16.         case plus:
  17.             value += arg;
  18.             break;
  19.         case minus:
  20.             value -= arg;
  21.             break;
  22.         case times:
  23.             value *= arg;
  24.             break;
  25.         case divide:
  26.             value /= arg;
  27.             break;
  28.         case equals:
  29.             value = arg;
  30.             break;
  31.         }
  32.         return value;
  33.     }
  34.  
  35.     @Override
  36.     public String toString() {
  37.         switch (this) {
  38.         case plus:
  39.             return "+";
  40.         case minus:
  41.             return "-";
  42.         case times:
  43.             return "*";
  44.         case divide:
  45.             return "/";
  46.         case equals:
  47.             return "=";
  48.         }
  49.         return "N";
  50.     }
  51.  
  52.     public static Amplifier parseAmplifier(char c) {
  53.         switch (c) {
  54.         case '+':
  55.             return plus;
  56.         case '-':
  57.             return minus;
  58.         case '*':
  59.             return times;
  60.         case '/':
  61.             return divide;
  62.         case '=':
  63.             return equals;
  64.         }
  65.         return null;
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment