package main
import (
"account/model"
"fmt"
)
func main() {
account := model.NewAccount("jzh111","123456",40)
if account != nil {
fmt.Println("建立OK")
}else {
fmt.Println("建立ERROR")
}
}
package model
import "fmt"
type account struct {
accountNo string
pwd string
balance float64
}
func NewAccount(accountNo string, pwd string, balance float64) *account {
if len(accountNo) < 6 || len(accountNo) > 10 {
fmt.Println("賬號的長度不對...")
return nil
}
if len(pwd) != 6 {
fmt.Println("密碼的長度不對...")
return nil
}
if balance < 20 {
fmt.Println("餘額數目不對...")
return nil
}
return &account{
accountNo: accountNo,
pwd: pwd,
balance: balance,
}
}
本作品採用《CC 協議》,轉載必須註明作者和本文連結