models
Class TernaryBalance

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

public class TernaryBalance
extends Balance


Constructor Summary
TernaryBalance(int number)
           
 
Method Summary
 void weigh(int x)
          In a ternary system we can weigh the required amount by placing weights in the left and right pans
 
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

TernaryBalance

public TernaryBalance(int number)
Parameters:
number - is the number of weights to be used in the weighing pans. All these weights will have binary integer values from 1 ... 3^(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 ternary system we can weigh the required amount by placing weights in the left and right pans

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.