Wallet - require 'Coin' #Coded by srihari jagan vasista...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
require 'Coin' #Coded by srihari jagan vasista #All the methods of the Wallet class like getCount,addCoin,removeCoin,printContent class Wallet c def initialize @wallet = Hash.new(0) @coin = Hash.new(0) end e def getCount(c = Coin.new("",0)) @count = 0 if(@wallet.has_key?(c.getName())) then count = @wallet[c.getName()] else count = 0 end return count end e def addCoin(coin = Coin.new("",0)) @coinName = ""; @coinValue = 0 begin if(!coin.getName().empty?)then @coinName = coin.getName(); end if(!coin.getValue()!= 0) then @coinValue = coin.getValue(); end rescue @coinName = "" @coinValue = 0 end if(!@coinName.eql?("") and !(@coinValue == 0) and (@coin.empty? or ! @coin.has_key?(@coinName))) then @coin.store(@coinName,@coinValue) end if(!@coinName.eql?("") and !(@coinValue == 0) and !@wallet.has_key? (@coinName)) then @wallet.store(@coinName,1) elsif(!@coinName.eql?("") and !(@coinValue == 0) and @wallet.has_key? (@coinName) and @coin.has_key?(@coinName))then
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

Wallet - require 'Coin' #Coded by srihari jagan vasista...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online