abstractions
Interface BalanceSpecification

All Known Implementing Classes:
Balance, BinaryBalance, TernaryBalance, UnrestrictedBalance

public interface BalanceSpecification

A balance has 2 pans - left and right - and a set of weights which can be in 1 of the 2 pans or unused on the table. The weight set cannot be changed after initialisation and weights can be moved between the table and the pans. Initially all weights should be on the table.

Version:
1
Author:
J Paul Gibson

Method Summary
 void addLeft(int x)
          Search for the specified weight on the table.
 void addRight(int x)
          Search for the specified weight on the table.
 int maxNumberOfWeights()
           
 int maxThatCanBeWeighed()
           
 void moveAllToTable()
          Move all weights in left and right pans to the table
 void removeLeft(int x)
          Search for the specified weight in the left pan.
 void removeRight(int x)
          Search for the specified weight in the right pan.
 void weigh(int x)
           
 int weighing()
           
 java.lang.String weightsInLeft()
           
 java.lang.String weightsInRight()
           
 

Method Detail

addLeft

void addLeft(int x)
Search for the specified weight on the table. If the weight is found then move it to the left pan. Otherwise do nothing.

Parameters:
x - is the weight that we wish to move

addRight

void addRight(int x)
Search for the specified weight on the table. If the weight is found then move it to the right pan. Otherwise do nothing.

Parameters:
x - is the weight that we wish to move

maxNumberOfWeights

int maxNumberOfWeights()
Returns:
the maximum number of weights shared between the table and the pans - this value should be constant after the system is initialised

maxThatCanBeWeighed

int maxThatCanBeWeighed()
Returns:
the maximum value that can be weighed : the total of all the weights

moveAllToTable

void moveAllToTable()
Move all weights in left and right pans to the table


removeLeft

void removeLeft(int x)
Search for the specified weight in the left pan. If the weight is found then move it back to the table. Otherwise do nothing.

Parameters:
x - is the weight that we wish to move

removeRight

void removeRight(int x)
Search for the specified weight in the right pan. If the weight is found then move it back to the table. Otherwise do nothing.

Parameters:
x - is the weight that we wish to move

weigh

void weigh(int x)
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.

weighing

int weighing()
Returns:
the difference between the total weights in the left and right pans

weightsInLeft

java.lang.String weightsInLeft()

weightsInRight

java.lang.String weightsInRight()