标签:foundation框架 设计 函数 ios开发
Cinema.m实现
#import "Cinema.h" @implementation Cinema -(id)init { //调用父类构造方法 self = [super init]; //判断初始化是否成功 if(self != nil) { _name = nil;//用来存储电影的名称 _price = 0;//用来存储电影票价 _rowNumber = 1;//用来存储座位排数 _seatNumber = 1;//用来存储座位号 _filmRoom = FilmRoomWithOne;//用来存储影厅号 } //返回self return self; } /*set\get方法的声明*/ /**提供电影名称的set方法*/ -(void)setName:(NSString *)name { _name = name; } -(NSString *)name; { return _name; } /**提供电影票价的set方法*/ -(void)setPrice:(int)price { if (price > 0) { _price = price; } } -(int)price { return _price; } /**提供电影院位排数的set方法*/ -(void)setRowNumber:(int)rowNumber { if (rowNumber > 0 && rowNumber < 11) { _rowNumber = rowNumber; } } -(int)rowNumber { return _rowNumber; } /**提供影厅座位号的set方法*/ -(void)setSeatNumber:(int)seatNumber { if (seatNumber > 0 && seatNumber< 15) { _seatNumber = seatNumber; } } -(int)seatNumber { return _seatNumber; } /**影厅选择*/ -(void)filmWithPlayFileRoom:(FilmRoom)filmRoom { switch (filmRoom) { case FilmRoomWithOne: NSLog(@"你选择的是1号影厅"); break; case FilmRoomWithTwo: NSLog(@"你选择的是2号影厅"); break; case FilmRoomWithThree: NSLog(@"你选择的是3号影厅"); break; case FilmRoomWithFour: NSLog(@"你选择的是4号影厅"); break; case FilmRoomWithFive: NSLog(@"你选择的是5号影厅"); break; case FilmRoomWithSix: NSLog(@"你选择的是6号影厅"); case FilmRoomWithSeven: NSLog(@"你选择的是7号影厅"); break; default: NSLog(@"请重新选择!谢谢"); break; } } NSString * _name;//用来存储电影的名称 int _price;//用来存储电影票价 int _rowNumber;//用来存储座位排数 int _seatNumber;//用来存储座位号 FilmRoom _filmRoom;//用来存储影厅号 /**重写description方法*/ -(NSString *)description { return [NSString stringWithFormat:@"电影名称:%@ 电影票价: %d 座位排数:%d 座位号:%d 影厅号:%d",_name,_price,_rowNumber,_seatNumber,_filmRoom]; } /*类方法实现*/ +(NSString *)getFilmRoom:(FilmRoom)filmRoom { NSString * room = @" "; switch (filmRoom){ case FilmRoomWithOne: room = @"你选择的是1号影厅"; break; case FilmRoomWithTwo: room = @"你选择的是2号影厅"; break; case FilmRoomWithThree: room = @"你选择的是3号影厅"; break; case FilmRoomWithFour: room = @"你选择的是4号影厅"; break; case FilmRoomWithFive: room = @"你选择的是5号影厅"; break; case FilmRoomWithSix: room = @"你选择的是6号影厅"; case FilmRoomWithSeven: room = @"你选择的是7号影厅"; break; default: room = @"请重新选择!谢谢" ; break; } return room; } //自定义构造函数 -(id)initWithFilm:(Film *)film { self = [super init]; if(self != nil) { _film = film; } return self; } -(void)setFilm:(Film *)film { _film = film; } -(Film *)film { return _film; } //建立两个类之间的组合关系 -(Film *)informationAboutFilm:(Film *)film { [film aboutTheFilm]; return film; } @end
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:foundation框架 设计 函数 ios开发
原文地址:http://blog.csdn.net/u012701023/article/details/46922277