1. App class
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_012
{
class App
{
public App()
{
Inventory inventory = new Inventory();
}
}
}
|
2. Inventory class
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_012
{
class Inventory
{
public List<Item> itemList;
public Inventory()
{
this.itemList = new List<Item>();
}
public void Add(Item item)
{
//itemlist에 item.name이 있는지 확인
//있다면
Item foundItem = null;
foreach(Item element in this.itemList)
{
{
foundItem = element;
break;
}
}
if(foundItem!=null)
{
//Console.WriteLine(foundItem.amount);
foreach (Item items in this.itemList)
{
}
}
else
{
//같은 이름이 없다면
}
}
public Item GetItemByName(string name)
{
Item foundItem = null;
foreach (Item item in itemList)
{
{
foundItem = item;
break;
}
}
//찾은 아이템이 null이 아니라면
//수량을 1 감소시킨다
//새로운 아이템을 생성한다.
//아이템의 이름은 찾은 아이템이다.
//수량은 1이다.
Item rtnItem = null;
if(foundItem!=null)
{
}
return rtnItem;
}
public void PrintAllName()
{
foreach (Item items in itemList)
{
}
}
}
}
|
3. Item class
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;
namespace Study_012
{
class Item
{
public string name;
public int amount;
public Item(string name, int amount)
{
this.name = name;
this.amount = amount;
}
}
}
|
4. 결과값
'C# > 수업내용' 카테고리의 다른 글
2020.04.21. 수업내용 - Json 파일 만들고 프로그램에 넣기 (0) | 2020.04.21 |
---|---|
2020.04.21. 수업내용 - Dictionary 개요 (0) | 2020.04.21 |
2020.04.20. 수업내용 - data 클래스 따로 만들기 (0) | 2020.04.21 |
2020.04.16. 수업내용 - 1) 문자열 분할하고 배열객체에 할당하기, 2) 배열 객체를 다른 클래스에 전달하기 (0) | 2020.04.16 |
2020.04.16. 수업내용 - 장바구니 (장바구니 클래스, 과일 클래스) (0) | 2020.04.16 |