Design and Implementation of the Bus card system for ios development, and ios development
//// Main. m // Bus-Bus/* Bus card recharge system. There are two options: the first option is coin or banknote, and the second option is card recharge. The value of recharge is 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]; // when the value is assigned here, the value is set to 100, resulting in a program error // [ChargeMachine recharge: KindOfMoney20]; [ChargeMachine recharge: KindOfMoneyCoinMoney2]; // [machine recharge: KindOfMoneyCoinMoney2]; NSLog (@ "% @", machine); return 0 ;}
# Import <Foundation/Foundation. h> # import "Money. h "@ interface Card: NSObject {/* Bus Card number */NSString * _ numberOfCard;/** amount of Bus Card storage */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 {/** is used to record the total sales volume */int countOfMoney; KindOfMoney _ money;} @ property int countOfMoney; /** print the ticket */-(void) sellTicket;/** recharge */+ (int) recharge :( KindOfMoney) kindOfMoney;-(int) recordcounOfMony; @ end
# Import "ChargeMachine. h "@ implementation ChargeMachine @ synthesize countOfMoney = _ countOfMoney;/** print the ticket */-(void) sellTicket {NSLog (@" sell a ticket ");} /** recharge */-(void) recharge {NSLog (@ "recharge successful");}-(int) recordcounOfMony {_ countOfMoney + = _ money; return _ countOfMoney ;} + (int) recharge :( KindOfMoney) kindOfMoney {ChargeMachine * machine = [[ChargeMachine alloc] init]; int moneyKind = 0; // int countOfMoney = 0; switch (ki NdOfMoney) {case KindOfMoney20: moneyKind = 20; // countOfMoney + = money; NSLog (@ "Your Recharge Amount is 20 RMB"); break; case KindOfMoney50: moneyKind = 50; NSLog (@ "Your Recharge Amount is 50 RMB"); // countOfMoney + = money; break; case KindOfMoney100: moneyKind = 100; NSLog (@ "Your Recharge Amount is 100 RMB"); // countOfMoney + = money; break; case KindOfMoneyCoinMoney2: moneyKind = 2; NSLog (@ "coins you cast"); [machine sellTicket]; break; case KindOfMoneyPaperMon Ey2: moneyKind = 2; NSLog (@ ""); [machine sellTicket]; break; default: break;} return moneyKind;}-(NSString *) description {// how do I save the value of a variable after multiple calls? // 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 {/** is used to store the variable */KindOfMoney20 with the top-up denomination, And/** is used to store the variable 50 with the top-up denomination */KindOfMoney50, /** variables used to store the top-up amount of 100 */KindOfMoney100, Alipay, KindOfMoneyPaperMoney2}; typedef enum KindOfMoney; @ interface Money: NSObject {KindOfMoney _ kindOfMoney ;} -(Money *) initWithKindOfMoney :( KindOfMoney) kindOfMoney; typedef enum KindOfMoney; @ end
#import "Money.h"@implementation Money{ }-(Money*)initWithKindOfMoney:(KindOfMoney)kindOfMoney{ self = [super init]; if (self!=nil) { _kindOfMoney = kindOfMoney; } return self;}@end
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.