Advertisement
Guest User

Untitled

a guest
Sep 1st, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // a op b == c
  2. class Equation {
  3.     final Operand a, b, c;
  4.     final Operation op;
  5.     Equation(Operand a, Operand b, Operand c, Operation op) {
  6.         this.a = a;
  7.         this.b = b;
  8.         this.c = c;
  9.         this.op = op;
  10.     }
  11.     static Equation createRandom(Random r) {
  12.         Operand[] abc = new Operand[3];
  13.         int missingIndex = r.newInt(3);
  14.         for (int i = 0; i < abc.length; i++) {
  15.             abc[i] = i == missingIndex
  16.                 ? new Missing()
  17.                 : new Operand(r.nextInt());
  18.         }
  19.         return new Equation(abc[0], abc[1], abc[2], new PlusOperation());
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement