#------------------------------------------------------------------------------- # page 2 of 12 # Shopoholic v 2.0 # code by cmpsr2000 # available exclusively @ rpgrevolution.com/forums # Released June 25, 2008 # #------------------------------------------------------------------------------- class Account < RPG::BaseItem attr_accessor :balance attr_accessor :type attr_accessor :interestRate #----------------------------------------------------------------------------- # Creates the account object # type: The type of account being created: # 0: Savings # 1: Checking # 2: Loan #----------------------------------------------------------------------------- def initialize(type) @type = type @name = Vocab::BankAccountNames[@type] @icon_index = Vocab::BankAccountIcons[@type] @description = Vocab::BankDescriptions[@type] @balance = 0 @interestRate = 0 end #----------------------------------------------------------------------------- # Deposits money into an account. Pays off loans. # amount: the amount being deposited #----------------------------------------------------------------------------- def deposit(amount) @balance = @type == 2 ? @balance - amount : @balance + amount end #----------------------------------------------------------------------------- # Removes money from the account. You can't withdraw from a loan, only pay it # off. # amount: the amount to withdraw from the account #----------------------------------------------------------------------------- def withdraw(amount) @balance = @type == 2 ? @balance : @balance - amount end #----------------------------------------------------------------------------- # Calculates interest for one term on this account. #----------------------------------------------------------------------------- def compound @balance += (@balance * @interestRate).ceil end end