Fluent Calculator


Create a calculator class that uses fluent syntax to perform addition and subtraction. It also supports undo and redo as part of the fluent syntax.

  • All input values should be int.
  • The calculator should never throw exceptions.
  • After the first call to Seed additional calls are ignored.

Examples

Examples
int result = new Calculator()
.Seed(10)
.Plus(5)
.Plus(5)
.Result(); // -> result = 20
int result = new Calculator()
.Seed(10)
.Plus(5)
.Minus(2)
.Undo()
.Undo() // -> 10
.Redo() // -> 15
.Result(); // -> result = 15

Hint

To avoid booleans when checking seed’s candidacy to be called, use method chaining with Progressive Interfaces. E.g Return an interface with which methods can be chained together instead of the Builder Object with all methods on it.

Bonus

Add a save method which when called saves the state of the previous operations. Undo or Redo operations called after a save have no effect.
int result = new Calculator()
.Seed(10)
.Plus(5)
.Minus(2)
.Save() // -> 13
.Undo()
.Redo()
.Undo()
.Plus(5)
.Result(); // -> result = 18