Design and Implementation of the Bus card system for ios development

Source: Internet
Author: User

Design and Implementation of the Bus card system for 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
 
  
# Import Card. h # import ChargeMachine. h # import Money. hint main (int argc, const char * argv []) {ChargeMachine * machine = [[ChargeMachine alloc] init]; // [machine sellTicket]; // [ChargeMachine recharge: kindOfMoney100]; // if the value is assigned here, the value is 100, causing a program error. // [ChargeMachine recharge: KindOfMoney20]; [ChargeMachine recharge: KindOfMoney50]; // [machine recharge: KindOfMoneyCoinMoney2]; NSLog (@%@, machine); return 0 ;}
 
# Import
 
  
# 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
 
  
# Import Money. h @ interface ChargeMachine: NSObject {/** used to record the total sales volume */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 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 (kindOfMo Ney) {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 when: moneyKind = 2; NSLog (@ you cast a coin); [machine sellTicket]; break; case KindOfMoneyPaperMoney2: moneyKind = 2; NSLog (@ your paper currency); [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
 
  
Enum KindOfMoney {/** is used to store the variable */KindOfMoney20 for the top-up denomination,/** is used to store the variable */KindOfMoney50 for the top-up denomination, /** 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


 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.