11일차 클래스(4)

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

서점

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

이름: 교보문고

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

책을 만든다

 

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

이름: 이것이C#이다

이름: 열혈자료구조

이름: 해로피터

 

요구사항

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

기본 생성자 메서드

 

 
Book.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 Syntax32
{
    public class Book
    {
        //데이터
        //이름
        public string name;
 
        public Book()
        {
 
        }
    }
 
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

 
BookStore.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Syntax32
{
    public class BookStore
    {
        //데이터
        //이름
        public string name;
 
        public BookStore()
        {
 
        }
 
        public Book MakeBook(string name)
        {
            var book = new Book();
            book.name = name;
            return book;
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
s

 

 
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
24
25
26
27
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Syntax32
{
    public class App
    {
        public App()
        {
            var bookstore1 = new BookStore();
            bookstore1.name = "교보문고";
            Console.WriteLine($"{bookstore1.name}이(가) 만들어졌습니다.");
            var book1 = bookstore1.MakeBook("이것이C#이다");
            var book2 = bookstore1.MakeBook("열혈자료구조");
            var book3 = bookstore1.MakeBook("해리포터");
 
            Console.WriteLine($"{book1.name}이(가) 만들어졌습니다.");
            Console.WriteLine($"{book2.name}이(가) 만들어졌습니다.");
            Console.WriteLine($"{book3.name}이(가) 만들어졌습니다.");
 
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
s

 

'Console Programming > C# Console' 카테고리의 다른 글

11일차 클래스(6)  (0) 2019.10.04
11일차 클래스(5)  (0) 2019.10.04
11일차 클래스(3)  (0) 2019.10.04
11일차 클래스(2)  (0) 2019.10.04
11일차 클래스 피자상점  (0) 2019.10.04
: