abstractions
Class Balance

java.lang.Object
  extended by abstractions.Balance
All Implemented Interfaces:
BalanceSpecification
Direct Known Subclasses:
BinaryBalance, TernaryBalance, UnrestrictedBalance

public abstract class Balance
extends java.lang.Object
implements BalanceSpecification


Constructor Summary
Balance(int numberOfWeights)
           
 
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.
 java.lang.String toString()
           
 int weighing()
           
 java.lang.String weightsInLeft()
           
 java.lang.String weightsInRight()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface abstractions.BalanceSpecification
weigh
 

Constructor Detail

Balance

public Balance(int numberOfWeights)
        throws java.lang.IllegalArgumentException
Parameters:
numberOfWeights - is the maximum number of weights that can be on the table or in the pans
Throws:
java.lang.IllegalArgumentException - if the numberOfWeights is not a positive integer;
Method Detail

addLeft

public void addLeft(int x)
Description copied from interface: BalanceSpecification
Search for the specified weight on the table. If the weight is found then move it to the left pan. Otherwise do nothing.

Specified by:
addLeft in interface BalanceSpecification
Parameters:
x - is the weight that we wish to move

addRight

public void addRight(int x)
Description copied from interface: BalanceSpecification
Search for the specified weight on the table. If the weight is found then move it to the right pan. Otherwise do nothing.

Specified by:
addRight in interface BalanceSpecification
Parameters:
x - is the weight that we wish to move

maxNumberOfWeights

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

maxThatCanBeWeighed

public int maxThatCanBeWeighed()
Specified by:
maxThatCanBeWeighed in interface BalanceSpecification
Returns:
the maximum value that can be weighed : the total of all the weights

moveAllToTable

public void moveAllToTable()
Description copied from interface: BalanceSpecification
Move all weights in left and right pans to the table

Specified by:
moveAllToTable in interface BalanceSpecification

removeLeft

public void removeLeft(int x)
Description copied from interface: BalanceSpecification
Search for the specified weight in the left pan. If the weight is found then move it back to the table. Otherwise do nothing.

Specified by:
removeLeft in interface BalanceSpecification
Parameters:
x - is the weight that we wish to move

removeRight

public void removeRight(int x)
Description copied from interface: BalanceSpecification
Search for the specified weight in the right pan. If the weight is found then move it back to the table. Otherwise do nothing.

Specified by:
removeRight in interface BalanceSpecification
Parameters:
x - is the weight that we wish to move

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

weighing

public int weighing()
Specified by:
weighing in interface BalanceSpecification
Returns:
the difference between the total weights in the left and right pans

weightsInLeft

public java.lang.String weightsInLeft()
Specified by:
weightsInLeft in interface BalanceSpecification

weightsInRight

public java.lang.String weightsInRight()
Specified by:
weightsInRight in interface BalanceSpecification