I have a question about Go Lang program. In this exercise, I try to pass the variable balance which initially $20,000 to deposit method with adding 3,000, then pass to withdraw method with subtract 2,500. However, the final balance is still 20,000. I do not know how to pass a variable in one method to another one, so I can get the final balance which supposed to be $20,500. Please help! Thank you so much in advance.
package main
import (
"fmt"
"time"
)
type Account struct {
id int
balance float64
annual_interest_rate float64
}
func (account Account) deposit(deposit1 float64) {
account.balance = account.balance - deposit1
}
func (account Account) withdraw(withdraw1 float64) {
account.balance = account.balance - withdraw1
}
func (account Account) getBalance() float64 {
return account.balance
}
func (account Account) getMonthlyInterest() float64 {
var monthlyInterestRate = account.annual_interest_rate / 1200
var monthly_interest = account.balance * monthlyInterestRate
return monthly_interest
}
func (account Account) getDateCreated() string {
var output string = ""
currentTime := time.Now()
output = currentTime.Format("Monday January,01 2006 15:04:15 PM")
return output
}
func main() {
var account = Account {id:1122, balance:20000, annual_interest_rate:4.5}
account.deposit(3000)
account.withdraw(2500)
fmt.Printf("Balance: $%.2f\n", account.getBalance())
fmt.Printf("Monthly Interest: $%.2f\n", account.getMonthlyInterest())
fmt.Printf("Date Created: %s\n", account.getDateCreated())
}