@fiy-fish
2015-07-15T09:05:24.000000Z
字数 1438
阅读 1423
Objective-c
// day03-01-处理练习
//
// Created by Aaron on 15/7/3.
// Copyright (c) 2015年 Aaron. All rights reserved.
//
#import <Foundation/Foundation.h>
/*
创建一个死期银行账户的类
属性:
账户号码
密码(加密)
存储金额
存储年限
方法:
构造方法
设置,账户号码,密码
存款
设置年限
取款
*/
#import "Bank.h"
//void test(Bank *b)
//{
// char str[20] = {'a','b','c'};
// [b setName:str];
//}
int main(int argc, const char * argv[]) {
@autoreleasepool {
Bank *bank = [[Bank alloc] initWithName:@"zhanghao" andSec:@"123456"];
//test(bank);
//...
//[bank showBank];
[bank saveMoney:10000];
[bank showBank];
[bank outMoney:1];
[bank showBank];
}
return 0;
}
#import <Foundation/Foundation.h>
/*
创建一个死期银行账户的类
属性:
账户号码
密码(加密)
存储金额
存储年限
方法:
构造方法
设置,账户号码,密码
存款
设置年限
取款
*/
@interface Bank : NSObject
{
NSString *_name;
NSString *_sec;
NSInteger _money;
NSInteger _age;
}
-(instancetype)initWithName:(NSString *)name andSec:(NSString *)sec;
-(void)setSec:(NSString *)sec;
//年限,提供一个设值方法即可
-(void)saveMoney:(NSInteger)money;
-(void)outMoney:(NSInteger)money;
-(void)setName:(NSString *)name;
//提供一个输出信息的方法
-(void)showBank;
@end
#import "Bank.h"
@implementation Bank
-(instancetype)initWithName:(NSString *)name andSec:(NSString *)sec
{
if(self = [super init])
{
_name = name;
_sec = sec;
}
return self;
}
-(void)setSec:(NSString *)sec
{
if(_sec != sec)
{
_sec = sec;
}
}
//年限,提供一个设值方法即可
-(void)saveMoney:(NSInteger)money
{
_money+=money;
}
-(void)outMoney:(NSInteger)money
{
_money-=money;
}
-(void)setName:(NSString *)name
{
if(_name != name)
{
_name = name;
}
}
-(void)showBank
{
NSLog(@"-----帐号: %@-----",_name);
NSLog(@"-----密码: ******-----");
NSLog(@"-----金额: %ld----",_money);
}
@end