Created
October 2, 2012 06:53
-
-
Save agushuley/3816922 to your computer and use it in GitHub Desktop.
Scala for impatients, chapter 5, 2th task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Account { | |
private var balance: Double = 0; | |
def credit = if ( balance < 0 ) -balance else 0 | |
def credit_=( value: Int ) { | |
balance = -value | |
} | |
def debit = if ( balance > 0 ) balance else 0 | |
def debit_=( value: Int ) { | |
balance = value | |
} | |
} | |
var myAccount = new Account() | |
myAccount.credit = 1 | |
println( "debit" -> myAccount.debit, "credit" -> myAccount.credit ) | |
myAccount.debit = 1 | |
println( "debit" -> myAccount.debit, "credit" -> myAccount.credit ) | |
myAccount.credit = -1 | |
println( "debit" -> myAccount.debit, "credit" -> myAccount.credit ) | |
myAccount.credit = 0 | |
println( "debit" -> myAccount.debit, "credit" -> myAccount.credit ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment