zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    1442. Count Triplets That Can Form Two Arrays of Equal XOR
    1441. Build an Array With Stack Operations
    312. Burst Balloons
    367. Valid Perfect Square
    307. Range Sum Query
    1232. Check If It Is a Straight Line
    993. Cousins in Binary Tree
    1436. Destination City
    476. Number Complement
    383. Ransom Note
  • 原文地址:https://www.cnblogs.com/0515offer/p/4570076.html
Copyright © 2011-2022 走看看