main.m// bus-bus /* Bus card recharge system, there are two options, the first input coins or banknotes to choose to buy tickets, the second type of card recharge, the value 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];//here assigns the value to be 100, causes the program error //[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{* * Bus card number */NSString * _ Numberofcard; /** Bus Card Storage amount */ 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{ /** to record total sales * / int Countofmoney; Kindofmoney _money; } @property int countofmoney;/** print ticket */-(void) sellticket;/** recharge */+ (int) Recharge: (Kindofmoney) kindofmoney;-(int) Recordcounofmony; @end
#import "ChargeMachine.h" @implementation chargemachine@synthesize Countofmoney = _countofmoney;/** print ticket */-(void) sellticket{NSLog (@ "sell a ticket"); /** Recharge */-(void) recharge{NSLog (@ "recharge successfully");} -(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 (@ "The amount you recharge is $20"); Break Case kindofmoney50:moneykind = 50; NSLog (@ "The amount you recharge is $50"); Countofmoney + = money; Break Case kindofmoney100:moneykind = 100; NSLog (@ "The amount you recharge is $100"); Countofmoney + = money; Break Case Kindofmoneycoinmoney2:moneykind = 2; NSLog (@ "You are voting for a coin"); [Machine Sellticket]; BrEak Case Kindofmoneypapermoney2:moneykind = 2; NSLog (@ "You are voting for banknotes"); [Machine Sellticket]; Break Default:break; } return moneykind;} -(NSString *) description{//After multiple calls how to save the value of a variable? 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 value of 20 */ KindOfMoney20, /** Used to store the variable value of 50 */ KindOfMoney50, /** used to store the variable value of 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
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Design and implementation of the bus card system for iOS development