ios开发之公交卡系统的设计与实现

2018-07-20    来源:open-open

容器云强势上线!快速搭建集群,上万Linux镜像随意使用
//
//  main.m
//  Bus-公交

/*
    公交一卡通充值系统,有两种功能选择,第一种投入硬币或者纸币
    选择购票,第二种一卡通充值,充值面额是20,50,100
 */
#import <Foundation/Foundation.h>
#import "Card.h"
#import "ChargeMachine.h"
#import "Money.h"

int main(int argc, const char * argv[])
{

    ChargeMachine * machine = [[ChargeMachine alloc]init];
    
    //[machine sellTicket];

    //[ChargeMachine recharge:KindOfMoney100];//这里赋值的时候赋值成为100,导致程序出错
    //[ChargeMachine recharge:KindOfMoney20];
    [ChargeMachine recharge:KindOfMoney50];
    [ChargeMachine recharge:KindOfMoneyCoinMoney2];
    //[machine recharge:KindOfMoneyCoinMoney2];
    NSLog(@"%@",machine);
    
    
    return 0;
}
#import <Foundation/Foundation.h>
#import "Money.h"


@interface Card : NSObject
{
    /*公交卡卡编号*/
    NSString * _numberOfCard;
    
    /**公交卡存放金额*/
    int MoneyOfCard;
    
}

@property NSString * numberOfCard;
@property int MoneyOfCard;
@end

#import "Card.h"

@implementation Card
@synthesize numberOfCard = _numberOfCard ;
@synthesize MoneyOfCard = _MoneyOfCard;




@end

#import <Foundation/Foundation.h>
#import "Money.h"
@interface ChargeMachine : NSObject
{
    /**用来记录销售总量*/
    int countOfMoney;
    
    KindOfMoney _money;
    
    
}


@property int countOfMoney;
/**打印票据*/
-(void)sellTicket;

/**充值*/
+(int)recharge:(KindOfMoney)kindOfMoney;

-(int)recordcounOfMony;

@end

#import "ChargeMachine.h"

@implementation ChargeMachine
@synthesize countOfMoney = _countOfMoney;
/**打印票据*/

-(void)sellTicket
{
    NSLog(@"卖出一张车票");
}

/**充值*/
-(void)recharge
{
    NSLog(@"充值成功");
}

-(int)recordcounOfMony
{
    _countOfMoney += _money;
    return _countOfMoney;
}

+(int)recharge:(KindOfMoney)kindOfMoney
{
    ChargeMachine * machine = [[ChargeMachine alloc]init];
    int moneyKind = 0;
    //int countOfMoney = 0;
    switch (kindOfMoney) {
        case KindOfMoney20:
            moneyKind = 20;
            //countOfMoney += money;
            NSLog(@"您充值的金额是20元");
            break;
        case KindOfMoney50:
            moneyKind = 50;
            NSLog(@"您充值的金额是50元");
            //countOfMoney += money;
            break;
        case KindOfMoney100:
            moneyKind = 100;
            NSLog(@"您充值的金额是100元");
            //countOfMoney += money;
            break;
        case KindOfMoneyCoinMoney2:
            moneyKind = 2;
            NSLog(@"您投的是硬币");
            [machine sellTicket];
            break;
        case KindOfMoneyPaperMoney2:
            moneyKind = 2;
            NSLog(@"您投的是纸币");
            [machine sellTicket];
            break;
        default:
            break;
    }
    return moneyKind;
}

-(NSString *)description
{
    //经过多次调用怎样保存一个变量的值?
    
    //ChargeMachine * machine = [[ChargeMachine alloc]init];
    //int moneyKind = [ChargeMachine recharge:_money];
    //int countOf_Money = [ChargeMachine recharge:_money];
    return [NSString stringWithFormat:@"%d",_money];
}
@end

#import <Foundation/Foundation.h>
enum KindOfMoney
{
    /**用来存储充值面额为20的变量*/
    KindOfMoney20,
    
    /**用来存储充值面额为50的变量*/
    KindOfMoney50,
    
    /**用来存储充值面额为100的变量*/
    KindOfMoney100,
    
    KindOfMoneyCoinMoney2,
    
    KindOfMoneyPaperMoney2
};

typedef enum KindOfMoney KindOfMoney;

@interface Money : NSObject
{
    KindOfMoney _kindOfMoney;
}
-(Money*)initWithKindOfMoney:(KindOfMoney)kindOfMoney;
typedef enum KindOfMoney KindOfMoney;
@end

#import "Money.h"

@implementation Money
{
    
}
-(Money*)initWithKindOfMoney:(KindOfMoney)kindOfMoney
{
    self = [super init];
    if (self!=nil) {
        _kindOfMoney = kindOfMoney;
    }
    return self;
}
@end


标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。

上一篇: js实现旋转的图片

下一篇:IOS网络编程---(数据请求+slider)将网络上的大文件下载到本地,并打印其进度