models
Class BinaryBalance

java.lang.Object
  extended by abstractions.Balance
      extended by models.BinaryBalance
All Implemented Interfaces:
BalanceSpecification

public class BinaryBalance
extends Balance


Constructor Summary
BinaryBalance(int number)
           
 
Method Summary
 void weigh(int x)
          In a binary system we can weigh the required amount by placing weights in the left pan only
 
Methods inherited from class abstractions.Balance
addLeft, addRight, maxNumberOfWeights, maxThatCanBeWeighed, moveAllToTable, removeLeft, removeRight, toString, weighing, weightsInLeft, weightsInRight
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BinaryBalance

public BinaryBalance(int number)
              throws java.lang.IllegalArgumentException
Parameters:
number - is the number of weights to be used in the weighing pans. All these weights will have binary integer values from 1 ... 2^(number-1)
Throws:
java.lang.IllegalArgumentException - if:
  • the number is not a positive integer,
  • the number is too large as it would result in an integer overflow error
Method Detail

weigh

public void weigh(int x)
In a binary system we can weigh the required amount by placing weights in the left pan only

Parameters:
x - is the weight that we wish to weigh in the right pan. This method should move the weights around in order to weigh this amount. If no exact solution is found then it should find a solution as close as possible to the one required.