Amazon.com Widgets Correction of Exercises 2 and 3
Welcome, Guest. Please login or register.
Did you miss your activation email?
June 19, 2013, 02:38:00 AM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Programming in Objective-C, 4th edition
| |-+  Exercises
| | |-+  Chapter 3
| | | |-+  Correction of Exercises 2 and 3
Pages: [1]   Go Down
Print
Author Topic: Correction of Exercises 2 and 3  (Read 718 times)
microapple
Jr. Member
**
Posts: 83



WWW Email




« on: August 13, 2012, 07:21:31 PM »

Code: (Objective-C)
/*
 This file implements a class called Phone, which
 represents Mobile Phones. Methods allow manipulation
 of the Phone , such as Calling, Sending Sms, Playing Games
 Listen to Music and Navigate in the Net

 */

#import <Foundation/Foundation.h>

//-----  @ Interface section ---------

  @interface Phone: NSObject

    -(NSString *) getColor;
    -(NSString *) getName;
    -(float) getPrice ;
    -(int) getIdPhone ;
    -(void) setColor: (NSString *) pColor ;
    -(void) setName: (NSString *) pName ;
    -(void) setPrice : (float) pPrice ;
    -(void) setIdPhone : (int) pIdPhone ;
    -(void) sendSms : (NSString *) pSms ;
    -(void) callNumber : (int) pNumber ;
    -(void) openUrl: (NSString *) pUrl ;
    -(void) listenMusic : (NSString *) pSongToListen ;
    -(void) playGame : (NSString *) pGameName ;
    -(void) print;

  @end

//-----  @ Implementation section ---------

@implementation Phone{
    int IdPhone ;
    float price ;
    NSString* name ;
    NSString* color;
}

-(NSString *) getColor{
    return color;
}

-(NSString *) getName{
    return name;
}

-(float) getPrice {
    return price ;
}

-(int) getIdPhone {
    return IdPhone;
}

-(void) setColor: (NSString *) pColor {
    color=pColor;
}

-(void) setName: (NSString *) pName {
    name=pName;
}

-(void) setPrice : (float) pPrice {
    price=pPrice;
}

-(void) setIdPhone : (int) pIdPhone {
    IdPhone=pIdPhone;
}

-(void) sendSms : (NSString *) pSms {
    // hope That I will learn it soon :p
    NSLog(@"Your SMS has been sent !");
}

-(void) callNumber : (int) pNumber {
    NSLog(@"Calling ...");
}

-(void) openUrl: (NSString *) pUrl {
    NSLog(@"Loading ...");
}

-(void) listenMusic : (NSString *) pSongToListen {
    NSLog(@"Listening ...");
}

-(void) playGame : (NSString *) pGameName {
    NSLog(@"Playing ...");
}

-(void) print {
    // didn't know how to make them in the same NSLog :s
    // keep getting The message :
    // Format string is not a string literal (potentially insecure)
    // but it works anyway :p I am just a beginner
    NSLog(@"Name : ");     
    NSLog(name);
    NSLog(@"Color : ");
    NSLog(color);
    NSLog(@"Price :");
    NSLog(@"%.2f",price);
}

@end

// Main Program Section

int main(int argc, const char * argv[]){
   
   
    @autoreleasepool{
       
        Phone *galaxyS3 = [[Phone alloc] init];
       
        [galaxyS3 setName:@"Galaxy S3"];
        [galaxyS3 setColor:@"White"];
        [galaxyS3 setIdPhone:1];
        [galaxyS3 setPrice:700];
       
        [galaxyS3 print];
       
        [galaxyS3 sendSms:@"Hello Moto"];
        [galaxyS3 playGame:@"Angry Birds"];
        [galaxyS3 callNumber:001657422115];
        [galaxyS3 openUrl:@"http://www.google.com"];
       
    }
   
}
Logged

Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.