com.billpringle.utils.wrputils
Class WrpMoney

java.lang.Object
  extended by com.billpringle.utils.wrputils.WrpMoney

public class WrpMoney
extends java.lang.Object

Class to encapsullate money values. This class represents money values. The money values are stored internally as BigDecimal variables. All BigDecimal numbers are created using Strings in the constructors to avoid loss of precision if converted to double.

Author:
Bill Pringle

Field Summary
private  java.math.BigDecimal amount
          the actual amount of money
private  int rounding
          method of rounding
private  int scale
          scale - the number of digits right of decimal place
 
Constructor Summary
WrpMoney()
          Default constructor
WrpMoney(java.math.BigDecimal val)
          Constructor using a BigDecimal value
WrpMoney(java.lang.String val)
          Constructor using a string
 
Method Summary
 WrpMoney add(java.math.BigDecimal val)
          Calculate the current value plus the given value This method calculates the sum of the current money value plus the specified amount and returns the result as a new object
 WrpMoney add(WrpMoney amt)
          Calculate the total of two money values Calculate the sum of this amount and the amount passed.
 void decrementBy(WrpMoney amt)
          Decrement the money amount by the specified value.
 WrpMoney divide(java.math.BigDecimal val)
          Divide money amount by specified value This method divides the amount of the current object by the specified value and returns a new object with that value
 WrpMoney divide(WrpMoney amt)
          Divide the current amount by the specified amount This method will divide the amount of this object by the amount stored in the parameter and return a new object with this amount
 void divideBy(java.math.BigDecimal val)
          Divide the current amount by the specified value This method divides the amount in the current object with the parameter value and updates the amount to that result
 void divideBy(WrpMoney amt)
          Divide the current amount by the specified amount This method will divide the amount of the current object with the amount specified in the parameter and udpate the current amount with the result
 java.lang.String format()
          Format the current amount This method returns a string with the current value formatted for currency.
 java.math.BigDecimal getAmount()
           
 int getRounding()
           
 int getScale()
           
 void incrementBy(java.math.BigDecimal val)
          Increment the money value by the amount specified This method will increment the internal amount of money by the specified value in the argument
 void incrementBy(WrpMoney amt)
          Increment the current amount by the specified amount This method increments the money value by the amount stored in the argument
static void main(java.lang.String[] args)
           
 WrpMoney multiply(java.math.BigDecimal amt)
          Multiply the current money amount by the specified value This method will multiply the value of this object by the specified amount and return the result in a new object.
 WrpMoney multiply(WrpMoney amt)
          Compute the product of two amounts.
 void multiplyBy(java.math.BigDecimal val)
          Multiply the current money value by the specified value This method multiplies the current money amount by the amount specified in the parameter
 void multiplyBy(WrpMoney amt)
          Multiply the current amount by the specified amount This method will multiply the money amount of this object by the value stored in the parameter
 void setAmount(java.math.BigDecimal amount)
           
 void setRounding(int rounding)
           
 void setScale(int scale)
           
 WrpMoney subtract(java.math.BigDecimal val)
          Calculate the difference of two money values This method subtracts the specified amount from the amount of this object and returns a new object with that difference
 WrpMoney subtract(WrpMoney amt)
          Subtract two money values Calculate the difference between the current amount and the amount passed.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

amount

private java.math.BigDecimal amount
the actual amount of money


scale

private int scale
scale - the number of digits right of decimal place


rounding

private int rounding
method of rounding

Constructor Detail

WrpMoney

public WrpMoney()
Default constructor


WrpMoney

public WrpMoney(java.lang.String val)
         throws java.lang.NumberFormatException
Constructor using a string

Parameters:
val - the value of the amount
Throws:
java.lang.NumberFormatException

WrpMoney

public WrpMoney(java.math.BigDecimal val)
Constructor using a BigDecimal value

Parameters:
val - the value of the amount
Method Detail

add

public WrpMoney add(WrpMoney amt)
Calculate the total of two money values Calculate the sum of this amount and the amount passed. Return the sum as a new object

Parameters:
amt - contains the amount to add to this amount
Returns:
a new WrpMoney object with the sum

add

public WrpMoney add(java.math.BigDecimal val)
Calculate the current value plus the given value This method calculates the sum of the current money value plus the specified amount and returns the result as a new object

Parameters:
val - the value to add
Returns:
a new WrpMoney object with the sum

incrementBy

public void incrementBy(WrpMoney amt)
Increment the current amount by the specified amount This method increments the money value by the amount stored in the argument

Parameters:
amt - contains the amount to be added

incrementBy

public void incrementBy(java.math.BigDecimal val)
Increment the money value by the amount specified This method will increment the internal amount of money by the specified value in the argument

Parameters:
val - the amount to add to the money amount

subtract

public WrpMoney subtract(WrpMoney amt)
Subtract two money values Calculate the difference between the current amount and the amount passed. Return the difference as a new object.

Parameters:
amt - contains the amount to subtract from this amount
Returns:
a new WrpMoney object with the difference

subtract

public WrpMoney subtract(java.math.BigDecimal val)
Calculate the difference of two money values This method subtracts the specified amount from the amount of this object and returns a new object with that difference

Parameters:
val - the amount to subtract from the current value
Returns:
a new object with the difference

decrementBy

public void decrementBy(WrpMoney amt)
Decrement the money amount by the specified value. This method will decrement the amount of this object by the value contained in the argument

Parameters:
amt - contains the amount to subtract

multiply

public WrpMoney multiply(WrpMoney amt)
Compute the product of two amounts. This method calculates the product of this amount with the specified amount. (probably an amount and a rate) and returns the result as a new object

Parameters:
amt - contains the amount to multiply this by
Returns:
a new WrpMoney object with the product

multiply

public WrpMoney multiply(java.math.BigDecimal amt)
Multiply the current money amount by the specified value This method will multiply the value of this object by the specified amount and return the result in a new object.

Parameters:
amt - the amount to multiply the amount of this object
Returns:
a new object with the product

multiplyBy

public void multiplyBy(WrpMoney amt)
Multiply the current amount by the specified amount This method will multiply the money amount of this object by the value stored in the parameter

Parameters:
amt - contains the amount to be multiplied by

multiplyBy

public void multiplyBy(java.math.BigDecimal val)
Multiply the current money value by the specified value This method multiplies the current money amount by the amount specified in the parameter

Parameters:
val - the amount to multiply this money amount

divide

public WrpMoney divide(WrpMoney amt)
Divide the current amount by the specified amount This method will divide the amount of this object by the amount stored in the parameter and return a new object with this amount

Parameters:
amt - amount to divide this money amount by
Returns:
new object with result in amount

divide

public WrpMoney divide(java.math.BigDecimal val)
Divide money amount by specified value This method divides the amount of the current object by the specified value and returns a new object with that value

Parameters:
val - the value to divide by
Returns:
a new object with the result

divideBy

public void divideBy(WrpMoney amt)
Divide the current amount by the specified amount This method will divide the amount of the current object with the amount specified in the parameter and udpate the current amount with the result

Parameters:
amt - the amount to divide by

divideBy

public void divideBy(java.math.BigDecimal val)
Divide the current amount by the specified value This method divides the amount in the current object with the parameter value and updates the amount to that result

Parameters:
val - the amount to divide by

format

public java.lang.String format()
Format the current amount This method returns a string with the current value formatted for currency. <.p>

Note:
Due to the need to convert from BigDecimal to double when using the NumberFormat Currency methods, some precision might be lost in the formatted string, but the actual amount is unaffected.

Returns:
the amount in currency format

getAmount

public java.math.BigDecimal getAmount()
Returns:
the amount

setAmount

public void setAmount(java.math.BigDecimal amount)
Parameters:
amount - the amount to set

getScale

public int getScale()
Returns:
the scale

setScale

public void setScale(int scale)
Parameters:
scale - the scale to set

getRounding

public int getRounding()
Returns:
the rounding

toString

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

setRounding

public void setRounding(int rounding)
Parameters:
rounding - the rounding to set

main

public static void main(java.lang.String[] args)
Parameters:
args -