OC1_银行账户类

//
//  BankAccount.h
//  OC1_银行账户类
//
//  Created by zhangxueming on 15/6/10.
//  Copyright (c) 2015年 zhangxueming. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface BankAccount : NSObject
{
    NSString *_account;
    NSString *_password;
    float    _money;
    int      _year;
}

//构造方法
- (id)initWithAccount:(NSString *)account andPassword:(NSString *)password;

//setter方法
- (void)setAccount:(NSString *)aAccount;
- (void)setPassword:(NSString *)aPassword;
- (void)setYear:(int)aYear;
- (void)setAccount:(NSString *)aAccount andPassword:(NSString *)aPassword;

//getter方法
- (NSString *)account;
- (NSString *)password;
- (float)money;
- (int)year;

//存款
- (float)saveMoney:(float)aMoney;

//取款
- (float)getMoney:(float)aMoney;

@end
//
//  BankAccount.m
//  OC1_银行账户类
//
//  Created by zhangxueming on 15/6/10.
//  Copyright (c) 2015年 zhangxueming. All rights reserved.
//

#import "BankAccount.h"

@implementation BankAccount

//构造方法
- (id)initWithAccount:(NSString *)account andPassword:(NSString *)password
{
    if (self = [super init]) {
        _account = account;
        _password = password;
    }
    return self;
}

//setter方法
- (void)setAccount:(NSString *)aAccount
{
    _account = aAccount;
}
- (void)setPassword:(NSString *)aPassword
{
    _password = aPassword;
}
- (void)setYear:(int)aYear
{
    _year = aYear;
}
- (void)setAccount:(NSString *)aAccount andPassword:(NSString *)aPassword
{
    _account = aAccount;
    _password = aPassword;
}

//getter方法
- (NSString *)account
{
    return _account;
}
- (NSString *)password
{
    return _password;
}
- (float)money
{
    return _money;
}
- (int)year
{
    return _year;
}

//存款
- (float)saveMoney:(float)aMoney
{
    return _money+=aMoney;
}

//取款
- (float)getMoney:(float)aMoney
{
    return _money-=aMoney;
}

@end
//
//  main.m
//  OC1_银行账户类
//
//  Created by zhangxueming on 15/6/10.
//  Copyright (c) 2015年 zhangxueming. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "BankAccount.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        BankAccount *bankAccount = [[BankAccount alloc] init];
        [bankAccount setAccount:@"13245678" andPassword:@"666666"];
        NSLog(@"account = %@ password = %@", [bankAccount account],[bankAccount password]);

        NSLog(@"money = %.2f", [bankAccount saveMoney:100001001]);
        NSLog(@"money = %.2f",[bankAccount getMoney:5000]);
    }
    return 0;
}

 

posted @ 2015-06-11 20:32  sirzhang  阅读(402)  评论(0编辑  收藏  举报
AmazingCounters.com