OC项目-我有一辆车

#ifndef ___PublicFile_h
#define ___PublicFile_h

enum _carModel{
    microCar,
    smallCar,
    familyCar,
    bigCar,
    SUV,
    MPV,
    sportCar,
    pickupCar
};

typedef enum _carModel CarModel;

typedef enum _color{
    red,
    white,
    black,
    blue,
    grey,
    yellow,
    green
}Color;

typedef struct _carSize{
    int length;
    int width;
    int high;
}CarSize;

typedef enum _gearbox{
    selfmotion,
    handmovement,
    selfAndHandMovement,
}Gearbox;

typedef enum _configuration{
    lowcon,
    middlecon,
    highcon
}Configuration;

typedef struct _time{
    int year;
    int month;
    int day;
}Time;

typedef enum _navigationSize{
    fiveInch,
    sixInch,
    sevenInch
}NavigationSize;

typedef enum _inputMode{
    handWritten,
    spell,
    fastSpell,
    handWrittenPen
}InputMode;

typedef struct _resolution{
    int left;
    int right;
}Resolution;
#endif

```

```
//
//  Screen.h
//  汽车
//
//  Created by 邱学伟 on 15/7/28.
//  Copyright (c) 2015年 jerehedu. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "PublicFile.h"
@interface Screen : NSObject
{
    
    NSString *_screenBrand;
    Resolution _resolution;
}

-(void)setScreenBrand:(NSString *)screenBrand;
-(NSString *)screenBrand;

-(void)resolution:(Resolution)resolution;
-(Resolution)resolution;

-(void)setScreenBrand:(NSString *)screenBrand andResolution:(Resolution)resolution;

+(instancetype)setScreenBrand:(NSString *)screenBrand andResolution:(Resolution)resolution;

-(void)printScreen;
@end

```

```
//
//  Screen.m
//  汽车
//
//  Created by 邱学伟 on 15/7/28.
//  Copyright (c) 2015年 jerehedu. All rights reserved.
//

#import "Screen.h"

@implementation Screen
-(void)setScreenBrand:(NSString *)screenBrand{
    _screenBrand=screenBrand;
}
-(NSString *)screenBrand{
    return _screenBrand;
}

-(void)resolution:(Resolution)resolution{
    _resolution=resolution;
}
-(Resolution)resolution{
    return _resolution;
}


-(void)setScreenBrand:(NSString *)screenBrand andResolution:(Resolution)resolution{
    _screenBrand=screenBrand;
    _resolution=resolution;
}

+(instancetype)setScreenBrand:(NSString *)screenBrand andResolution:(Resolution)resolution{
    Screen *screen = [Screen new];
    [screen setScreenBrand:screenBrand andResolution:resolution];
    return screen;
}
-(void)printScreen{
    NSLog(@"屏幕的品牌是:%@,分辨率为%i*%i",_screenBrand,_resolution.left,_resolution.right);
}

@end

```

```
//
//  Navigation.h
//  汽车
//
//  Created by 邱学伟 on 15/7/28.
//  Copyright (c) 2015年 jerehedu. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "PublicFile.h"
#import "Screen.h"
@interface Navigation : NSObject
{
    NSString *_brand;
    float _price;
    NavigationSize _navigationSize;
    Color _navigationColor;
    InputMode _inputMode;
    int _memory;//内存
    BOOL _backCarView;//倒车影像
    
    @public Screen *_screen;//屏幕类
}

-(NSString*)brand;
-(float)price;
-(NavigationSize)navigationSize;
-(Color)navigationColor;
-(InputMode)inputMode;
-(int)memory;
-(BOOL)backCarView;
-(Screen*)screen;

-(void)setBrand:(NSString *)brand setPrice:(float)price setNavigationSize:(NavigationSize)navigationSize setNavigationColor:(Color)navigationColor  setInputMode:(InputMode)inputMode setMemory:(int)memory setBackCarView:(BOOL)backCarView setScreen:(Screen*)screen;

+(instancetype)setBrand:(NSString *)brand setPrice:(float)price setNavigationSize:(NavigationSize)navigationSize setNavigationColor:(Color)navigationColor  setInputMode:(InputMode)inputMode setMemory:(int)memory setBackCarView:(BOOL)backCarView setScreen:(Screen*)screen;

-(void)printNavigation;

-(NSString*)getNavigationSize:(NavigationSize)navigationSize;

-(NSString*)getNavigationColor:(Color)color;

-(NSString*)getInputMode:(InputMode)inputMode;

-(NSString*)getBackCarView:(BOOL)backCarView;
@end

```

```
//
//  Navigation.m
//  汽车
//
//  Created by 邱学伟 on 15/7/28.
//  Copyright (c) 2015年 jerehedu. All rights reserved.
//

#import "Navigation.h"

@implementation Navigation
-(void)setBrand:(NSString *)brand setPrice:(float)price setNavigationSize:(NavigationSize)navigationSize setNavigationColor:(Color)navigationColor  setInputMode:(InputMode)inputMode setMemory:(int)memory setBackCarView:(BOOL)backCarView setScreen:(Screen*)screen{
    _brand=brand;
    _price=price;
    _navigationSize=navigationSize;
    _navigationColor=navigationColor;
    _inputMode=inputMode;
    _memory=memory;
    _backCarView=backCarView;
    _screen=screen;
}

-(NSString*)brand{
    return _brand;
}
-(float)price{
    return _price;
}
-(NavigationSize)navigationSize{
    return _navigationSize;
}
-(Color)navigationColor{
    return _navigationColor;
}
-(InputMode)inputMode{
    return _inputMode;
}
-(int)memory{
    return _memory;
}
-(BOOL)backCarView{
    return _backCarView;
}
-(Screen*)screen{
    return _screen;
}

+(instancetype)setBrand:(NSString *)brand setPrice:(float)price setNavigationSize:(NavigationSize)navigationSize setNavigationColor:(Color)navigationColor  setInputMode:(InputMode)inputMode setMemory:(int)memory setBackCarView:(BOOL)backCarView setScreen:(Screen*)screen{
    Navigation *navigat = [Navigation new];
   [navigat setBrand:brand setPrice:price setNavigationSize:navigationSize setNavigationColor:navigationColor setInputMode:
    inputMode setMemory:memory setBackCarView:backCarView setScreen:screen];
    return navigat;
    
}

-(void)printNavigation{
    NSLog(@"导航器品牌是:%@,参考价格为:%f元,尺寸是:%@,颜色是:%@色,输入方式为:%@,内存是:%iG,倒车影像:%@,导航器屏幕信息:屏幕的品牌是:%@,分辨率为%i*%i",_brand,_price,[self getNavigationSize:_navigationSize],[self getNavigationColor:_navigationColor],[self getInputMode:_inputMode],_memory,[self getBackCarView:_backCarView],[_screen screenBrand],[_screen resolution].left,[_screen resolution].right);
}

-(NSString*)getNavigationSize:(NavigationSize)navigationSize{
    NSString *str = [NSString new];
    switch (navigationSize) {
        case fiveInch:
            str=@"5寸";
            break;
        case sixInch:
            str=@"6寸";
            break;
        case sevenInch:
            str=@"7寸";
            break;
        default:
            break;
    }
    return str;
}

-(NSString*)getNavigationColor:(Color)color{
    NSString *str = [[NSString alloc]init];
    switch (color) {
        case red:
            str=@"红色";
            break;
        case white:
            str=@"白色";
            break;
        case black:
            str=@"黑色";
            break;
        case blue:
            str=@"蓝色";
            break;
        case grey:
            str=@"灰色";
            break;
        case yellow:
            str=@"黄色";
            break;
        case green:
            str=@"绿色";
            break;
        default:
            break;
    }
    return str;
}

-(NSString*)getInputMode:(InputMode)inputMode{
    NSString *str = [[NSString alloc]init];
    switch (inputMode) {
        case handWritten:
            str=@"手写";
            break;
        case spell:
            str=@"拼音";
            break;
        case fastSpell:
            str=@"拼音查询";
            break;
        case handWrittenPen:
            str=@"手写笔";
            break;
        default:
            break;
    }
    return str;
}

-(NSString*)getBackCarView:(BOOL)backCarView{
    NSString *str = [[NSString alloc]init];
    switch (backCarView) {
        case YES:
            str=@"有";
            break;
        case NO:
            str=@"没有";
            break;
        default:
            break;
    }
    return str;
}
@end

```

```
//
//  Car.h
//  汽车
//
//  Created by 邱学伟 on 15/7/28.
//  Copyright (c) 2015年 jerehedu. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "PublicFile.h"
#import "Navigation.h"
#import "Screen.h"
@interface Car : NSObject
{
    NSString *_brand;
    CarModel _car;
    Color _carColor;
    float _peace;
    CarSize _carSize;
    Gearbox _gearbox;
    Configuration _configuration;
    Time _time;
    int _allcoverTime;//质保年限
    float _speed;//时速
    float _oilwear;//油耗
    BOOL _skylight;//天窗
    float _oilmeter;//油表
    
    Navigation *_navigation;//导航
}

-(float)firingCar;

-(void)stopCar;

-(float)addOil;

-(void)setBrand:(NSString*)brand setCar:(CarModel)car setCarColor:(Color)carColor setPeace:(float)peace setSize:(CarSize)carSize setGearbox:(Gearbox)gearbox setConfiguration:(Configuration)configuration setTime:(Time)time setAllcoverTime:(int)allcoverTime setSpeed:(float)speed setOilwear:(float)oilwear setSkylight:(BOOL)skylight setOilmeter:(float)oilmeter setNavigation:(Navigation *)navigation;

+(instancetype)setBrand:(NSString*)brand setCar:(CarModel)car setCarColor:(Color)carColor setPeace:(float)peace setSize:(CarSize)carSize setGearbox:(Gearbox)gearbox setConfiguration:(Configuration)configuration setTime:(Time)time setAllcoverTime:(int)allcoverTime setSpeed:(float)speed setOilwear:(float)oilwear setSkylight:(BOOL)skylight setOilmeter:(float)oilmeter setNavigation:(Navigation *)navigation;

-(void)printCar;

-(NSString*)getCar:(CarModel)car;//获取汽车类型
-(NSString*)getCarColor:(Color)color;//获取汽车颜色
-(NSString*)getGearbox:(Gearbox)gearbox;//获取变速箱类型
-(NSString*)getConfiguration:(Configuration)configuration;//获取配置
@end

```

```
//
//  Car.m
//  汽车
//
//  Created by 邱学伟 on 15/7/28.
//  Copyright (c) 2015年 jerehedu. All rights reserved.
//

#import "Car.h"

@implementation Car

-(float)firingCar{
    _oilmeter--;
    return _oilmeter;
}

-(void)stopCar{
    NSLog(@"汽车停止");
}

-(float)addOil{
    _oilmeter++;
    return _oilmeter;
}

-(void)setBrand:(NSString*)brand setCar:(CarModel)car setCarColor:(Color)carColor setPeace:(float)peace setSize:(CarSize)carSize setGearbox:(Gearbox)gearbox setConfiguration:(Configuration)configuration setTime:(Time)time setAllcoverTime:(int)allcoverTime setSpeed:(float)speed setOilwear:(float)oilwear setSkylight:(BOOL)skylight setOilmeter:(float)oilmeter setNavigation:(Navigation *)navigation{
    _brand=brand;
    _car=car;
    _carColor=carColor;
    _peace=peace;
    _carSize=carSize;
    _gearbox=gearbox;
    _configuration=configuration;
    _time=time;
    _allcoverTime=allcoverTime;
    _speed=speed;
    _oilwear=oilwear;
    _skylight=skylight;
    _oilmeter=oilmeter;
    _navigation=navigation;
    
}

+(instancetype)setBrand:(NSString*)brand setCar:(CarModel)car setCarColor:(Color)carColor setPeace:(float)peace setSize:(CarSize)carSize setGearbox:(Gearbox)gearbox setConfiguration:(Configuration)configuration setTime:(Time)time setAllcoverTime:(int)allcoverTime setSpeed:(float)speed setOilwear:(float)oilwear setSkylight:(BOOL)skylight setOilmeter:(float)oilmeter setNavigation:(Navigation *)navigation{
    Car *car0=[[Car alloc]init];
    [car0 setBrand:brand setCar:car setCarColor:carColor setPeace:peace setSize:carSize setGearbox:gearbox setConfiguration:configuration setTime:time setAllcoverTime:allcoverTime setSpeed:speed setOilwear:oilwear setSkylight:skylight setOilmeter:oilmeter setNavigation:navigation];
    return car0;
}

-(void)printCar{
    NSLog(@"汽车的品牌是:%@,车型是:%@,车的颜色是:%@色,汽车的参考价格为:%f元,汽车的尺寸为:%i*%i*%i ,变速箱是:%@的,该车配置是:%@的,上市日期是:%i年%i月%i日,质保年限是:%i年,时速:%f km/h, 油耗是:%f 个油,%@ 天窗,油表 %f L,该车导航器的信息是:导航器品牌是:%@,参考价格为:%f元,尺寸是:%@,颜色是:%@色,输入方式为:%@,内存是:%iG,倒车影像:%@,导航器屏幕信息:屏幕的品牌是:%@,分辨率为%i*%i",_brand,[self getCar:_car],[self getCarColor:_carColor],_peace,_carSize.length,_carSize.width,_carSize.high,[self getGearbox:_gearbox],[self getConfiguration:_configuration],_time.year,_time.month,_time.day,_allcoverTime,_speed,_oilwear,[self getSkylight:_skylight],_oilmeter,[_navigation brand],[_navigation price],[_navigation getNavigationSize:_navigation.navigationSize],[_navigation getNavigationColor:_navigation.navigationColor],[_navigation getInputMode:_navigation.inputMode],[_navigation memory],[_navigation getBackCarView:_navigation.backCarView],_navigation->
          _screen.screenBrand,_navigation.screen.resolution.left,_navigation.screen.resolution.right);
}

-(NSString*)getCar:(CarModel)car{//获取汽车类型
    NSString *str;
    switch (car) {
        case microCar:
            str=@"微型车";
            break;
        case smallCar:
            str=@"小型车";
            break;
        case familyCar:
            str=@"中型车";
            break;
        case bigCar:
            str=@"大型车";
            break;
        case SUV:
            str=@"SUV";
            break;
        case MPV:
            str=@"MPV";
            break;
        case sportCar:
            str=@"跑车";
            break;
        case pickupCar:
            str=@"皮卡";
            break;
        default:
            break;
    }
    return str;
}

-(NSString*)getCarColor:(Color)color{//获取汽车颜色
    NSString *str;
    switch (color) {
        case red:
            str=@"红色";
            break;
        case white:
            str=@"白色";
            break;
        case black:
            str=@"黑色";
            break;
        case blue:
            str=@"蓝色";
            break;
        case grey:
            str=@"灰色";
            break;
        case yellow:
            str=@"黄色";
            break;
        case green:
            str=@"绿色";
            break;
        default:
            break;
    }
    return str;
}

-(NSString*)getGearbox:(Gearbox)gearbox{//获取变速箱类型
    NSString *str;
    switch (gearbox) {
        case selfmotion:
            str=@"自动挡";
            break;
        case handmovement:
            str=@"手动挡";
            break;
        case selfAndHandMovement:
            str=@"手自一体挡";
        default:
            break;
    }
    return str;
}

-(NSString*)getConfiguration:(Configuration)configuration{//获取配置
    NSString *str;
    switch (configuration) {
        case lowcon:
            str=@"低配";
            break;
        case middlecon:
            str=@"中配";
            break;
        case highcon:
            str=@"高配";
        default:
            break;
    }
    return str;
}

-(NSString*)getSkylight:(BOOL)skylight{//获取天窗配置
    NSString *str;
    switch (skylight) {
        case YES:
            str=@"有";
            break;
        case NO:
            str=@"没有";
            break;
        default:
            break;
    }
    return str;
}
@end


```

```
//
//  main.m
//  汽车
//
//  Created by 邱学伟 on 15/7/28.
//  Copyright (c) 2015年 jerehedu. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "PublicFile.h"
#import "Car.h"
#import "Navigation.h"
#import "Screen.h"
/*
 使用面向对象的思想描述车类
 
 汽车类:
 属性:
 品牌  字符串
 车型  (枚举值:微型车、小型车、中型车、大型车、SUV、MPV、跑车、皮卡)
 颜色  (枚举值:红色、白色、黑色、蓝色、灰色、黄色、绿色…)
 参考价格    浮点
 尺寸 (结构体:长、宽、高)
 变速箱 (枚举值:自动、手动、手自一体)
 配置  (枚举:低配、中配、高配)
 上市日期  (结构体)
 质保年限   整型
 时速  浮点
 油耗    浮点
 天窗   布尔
 油表  浮点
 导航
 
 方法:1、成员变量的set、get方法
 2、启动  (每启动一次,油减少一点)
 3、停止
 4、加油 (油表改变)
 4、类方法得到对象
 5、类方法得到一个已经实现多个实例变量赋值的对象
 6、汽车信息展示
 
 导航类
 属性:
 品牌  字符串
 参考价格    浮点
 尺寸 (枚举:5英寸、6英寸、7英寸)
 颜色  (枚举值)
 输入方式 (枚举:手写、拼音、快拼查询、手写笔)
 内存  (8/16/32/64)
 倒车影像  布尔
 屏幕
 
 方法:1、成员变量的set、get方法
 2、对象方法多参设置
 3、类方法多参设置
 4、展示信息
 
 屏幕类
 属性:
 品牌  字符串
 分辨率 (例:800*480)
 
 方法:1、成员变量的set、get方法
 2、对象方法多参设置
 3、类方法多参设置
 4、展示信息
 */
int main(int argc, const char * argv[]) {
    @autoreleasepool {
        Navigation *navigetion1=[[Navigation alloc]init];
        
        Screen *screen1=[[Screen alloc]init];
        
        Car *car1=[[Car alloc]init];
        
        Resolution resolution1;
        resolution1.left=1280;
        resolution1.right=998;
        
        CarSize carSize1;
        carSize1.length=1024;
        carSize1.width=998;
        carSize1.high=688;
        
        Time time1;
        time1.year=2015;
        time1.month=9;
        time1.day=6;
        
        
        [screen1 setScreenBrand:@"三星" andResolution:resolution1];
        [screen1 printScreen];
        
        [navigetion1 setBrand:@"高德" setPrice:999 setNavigationSize:sixInch setNavigationColor:red setInputMode:handWritten setMemory:64 setBackCarView:YES setScreen:screen1];
        [navigetion1 printNavigation];
        
        [car1 setBrand:@"奔驰" setCar:SUV setCarColor:red setPeace:500000 setSize:carSize1 setGearbox:selfAndHandMovement setConfiguration:middlecon setTime:time1 setAllcoverTime:3 setSpeed:230 setOilwear:7 setSkylight:NO setOilmeter:122 setNavigation:navigetion1];
        [car1 printCar];
    }
    return 0;
}

你可能感兴趣的:(Objective-C)