ios開發之電子優惠券的設計與實現
//// main.m// 電子優惠券//#import #import Discount.h#import Food.hint main(int argc, const char * argv[]){ Discount * dis = [[Discount alloc]init]; [dis showInformation:20 andDiscountTime:@本優惠券每日上午10:30之後使用 andContentInformation:@本優惠券僅限在中國大陸地區售賣優惠券產品的麥當勞餐廳使用,具體以本店內公示為準,有效期間2013年12月4日-2013年12月30日;塗改或損壞無效;食品以實物為準,圖片僅供參考;本優惠券不合適用於送餐服務;除食物外,其他物品(包括容器)不在售賣範圍;本優惠券不能與其他優惠活動同時使用]; @autoreleasepool { // insert code here... NSLog(@Hello, World!); } return 0;}
//// Discount.h// 電子優惠券//#import @interface Discount : NSObject{ /**用來記錄打折價格*/ int _price; /**用來記錄打折使用的時間*/ NSString * _discountTime; /**最終解釋權資訊*/ NSString * _contentInformation;}@property int price;@property NSString * discountTime;@property NSString * contentInformation;-(void)showInformation:(int)price andDiscountTime:(NSString *)discountTime andContentInformation:(NSString *)contentInformation;@end
//// Discount.m// 電子優惠券//#import Discount.h@implementation Discount@synthesize price = _price;@synthesize discountTime = _discountTime;@synthesize contentInformation = _contentInformation;-(void)showInformation:(int)price andDiscountTime:(NSString *)discountTime andContentInformation:(NSString *)contentInformation{ _price = price; _discountTime = discountTime; _contentInformation = contentInformation; NSLog(@價格:%d 打折時間:%@ 詳細介紹:%@,_price,_discountTime,_contentInformation);}-(NSString *)description{ return [NSString stringWithFormat:@價格:%d 打折時間:%@ 詳細資料%@,_price,_discountTime,_contentInformation];}@end
//// Food.h// 電子優惠券//#import @interface Food : NSObject{ /**用來記錄菜品名稱*/ NSString * _foodName; /**組成材料*/ NSString * _material; /**營養資訊*/ NSString * _nutrition; /**用來記錄食品種類*/ NSString * _kindOfFood;}@property NSString * foodName;@property NSString * material;@property NSString * nutrition;@property NSString * kindOfFood;-(void)showInformation:(NSString*)foodName andShowMaterial:(NSString *)material andShowNurition:(NSString *)nutrition;@end
//// Food.m// 電子優惠券//#import Food.h@implementation Food@synthesize foodName = _foodName;@synthesize material = _material;@synthesize nutrition = _nutrition;@synthesize kindOfFood = _kindOfFood;-(void)showInformation:(NSString*)foodName andShowMaterial:(NSString *)material andShowNurition:(NSString *)nutrition;{ _foodName = foodName; _material = material; _nutrition = nutrition; NSLog(@%@ %@ %@,_foodName,_material,_nutrition);}-(NSString *)description{ return [NSString stringWithFormat:@食品名稱:%@食材:%@ 營養物質:%@,_foodName,_material,_nutrition];}@end