11일차 클래스(2)

Console Programming/C# Console 2019. 10. 4. 14:17

자판기

------------------

이름: 음료자판기

------------------

음료를 만든다

 

음료

------------------

이름: 칠성사이다

이름: 비락식혜

이름: 코카콜라

 

요구사항

------------------

생성자 메서드 (매개변수)

 

 

 
Drink.cs
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Syntax29
{
    public class Drink
    {
        //데이터
        //이름
        public string name;
        public Drink(string name)
        {
            this.name = name;
            Console.WriteLine($"{this.name}이(가) 나왔습니다.");
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

 
VendingMachine.cs
 
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
29
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Syntax29
{
    
    public class VendingMachine
    {
        //데이터
        //이름
        public string name;
        public VendingMachine(string name)
        {
            this.name = name;
            Console.WriteLine($"{this.name}이(가) 생성되었습니다.");
        }
 
        public Drink TakeDrnik(string name)
        {
            Drink drink = new Drink(name);
 
            return drink;
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 
 
App.cs
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System;
using System.Collections.Generic;
 
namespace Syntax29
{
    public class App
    {
        public App()
        {
            VendingMachine vendingmachin1 = new VendingMachine("음료자판기");
 
 
            Drink drink1 = new Drink("칠성사이다");
            Drink drink2 = new Drink("비락식혜");
            Drink drink3 = new Drink("코카콜라");
 
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

: