10.07 class 활용해 자동차만들기

C#/실습 2019. 10. 7. 16:56

코드:

 

1
2
3
4
5
6
7
8
9
10
11
12
public App()
        {
            Engine engine = new Engine("호준엔진");
            Wheel wheel = new Wheel("호준타이어");
            Car car = new Car("BMW");
            car.SetEngine(engine);
            car.SetWheel(wheel);
            var carEngine = car.GetEngine();
            var carWheel = car.GetWheel();
            Console.WriteLine($"{car.name}의 엔진은 {carEngine.name}이고, 타이어는 {carWheel.name}입니다.");
 
        }
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Car
    {
        public string name;
        Engine engine;
        Wheel wheel;
        public Car(string name)
        {
            this.name = name;
        }
        public void SetEngine(Engine engine)
        {
            this.engine = engine;
            Console.WriteLine(engine.name + "을 설치했습니다.");
        }
        public void SetWheel(Wheel wheel)
        {
            this.wheel = wheel;
            Console.WriteLine(wheel.name + "을 설치했습니다.");
        }
        public Engine GetEngine()
        {
            return this.engine;
        }
        public Wheel GetWheel()
        {
            return this.wheel;
        }
    }
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 
1
2
3
4
5
6
7
8
class Engine
    {
        public string name;
        public Engine(string name)
        {
            this.name = name;
        }
    }
 
1
2
3
4
5
6
7
8
class Wheel
    {
        public string name;
        public Wheel(string name)
        {
            this.name = name;
        }
    }
 

'C# > 실습' 카테고리의 다른 글

10.07 class 활용해 1955버거 만들기  (0) 2019.10.07
10.07 Class 활용해 BurgerSet 만들기  (0) 2019.10.07
10.02 컴퓨터 조립  (0) 2019.10.02
10.02 자동차 부품설정  (0) 2019.10.02
10.02 버거세트  (0) 2019.10.02
: