1. 코드
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace study_016_2
{
public enum eAnimal
{
강아지,
고양이,
송아지,
얼룩말,
}
class Town //
{
public List<string> YouthAnimalList;
public List<string> OlderAnimalList;
public Town()
{
YouthAnimalList = new List<string>();
OlderAnimalList = new List<string>();
}
}
class App
{
public App()
{
Town animalNames = new Town();
string MagicOfYouth = "아기 ";
string MagicOfRapidAging = "폭싹 늙은 ";
eAnimal[] animal = new eAnimal[4];
{
animal[i] = (eAnimal)i;
}
Console.WriteLine("-------------------------------");
Console.WriteLine("마녀의 숲에 오신 것을 환영합니다.");
Console.WriteLine("마을의 동물들에게 어떤 마법을 시전하시겠습니까?");
Console.WriteLine("[1. 젊음의 마법, 2. 노화의 마법]");
int select = this.SelectMagic();
switch (select)
{
case 1:
{
Console.WriteLine("-------------------------------");
animalNames.YouthAnimalList = this.MagicOfYouth(animal, MagicOfYouth);
this.PrintAnimalList(animalNames.YouthAnimalList);
break;
}
case 2:
{
Console.WriteLine("-------------------------------");
animalNames.OlderAnimalList = this.MagicOfRapidAging(animal, MagicOfRapidAging);
this.PrintAnimalList(animalNames.OlderAnimalList);
break;
}
}
Console.WriteLine("-------------------------------");
}
public int SelectMagic()
{
int input = Convert.ToInt32(Console.ReadLine());
return input;
}
public List<string> MagicOfYouth(eAnimal[] animal, string MagicOfYouth)
{
List<string> youngList = new List<string>();
foreach (eAnimal data in animal)
{
youngList.Add(MagicOfYouth + data);
}
return youngList;
}
public List<string> MagicOfRapidAging(eAnimal[] animal, string MagicOfRapidAging)
{
List<string> oldList = new List<string>();
foreach (eAnimal data in animal)
{
oldList.Add(MagicOfRapidAging + data);
}
return oldList;
}
public void PrintAnimalList(List<string> namelist)
{
Console.WriteLine("시전하신 마법의 결과입니다.");
foreach(string data in namelist)
{
Console.WriteLine(data);
}
}
}
}
|
2. 결과값
1)
2)