Guest User

Untitled

a guest
May 6th, 2018
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace PeopleManagement
  5. {
  6. class Person
  7. {
  8. public int Number;
  9. public string Name;
  10. public string Phone, Email, year;
  11.  
  12. public Person(string name, string phone, string email)
  13. {
  14. Name = name;
  15. Phone = phone;
  16. Email = email;
  17. }
  18.  
  19. public Person()
  20. {
  21. }
  22.  
  23. public virtual void personal_info()
  24. {
  25. Console.Write($"순번 : {Number} 이름 : {Name} 전화번호 : {Phone} 이메일 : {Email}");
  26. }
  27. }
  28.  
  29. class Student : Person
  30. {
  31. private readonly int _studentNumber;
  32. private int _price;
  33. private new int year; // 학년
  34. private readonly string _major;
  35.  
  36. public Student(string name, string phone, string email, int studentNumber, string major, int year) : base(name, phone, email)
  37. {
  38. _studentNumber = studentNumber;
  39. _major = major;
  40. this.year = year;
  41. }
  42.  
  43. public Student()
  44. {
  45. }
  46.  
  47. public int Price
  48. {
  49. get => _price;
  50. set
  51. {
  52. if (value > 500)
  53. {
  54. Console.WriteLine("최대 수혜 장학금은 500이 넘지 않아야 함");
  55. }
  56. else
  57. {
  58. _price = value;
  59. }
  60. }
  61. }
  62.  
  63. public override void personal_info()
  64. {
  65. Console.WriteLine($"순번 : {Number} 이름 : {Name} 전화번호 : {Phone} 이메일 : {Email} 학번 : {_studentNumber} " +
  66. $"학과 : {_major} 학년 : {year} 장학금 : {Price}");
  67. }
  68. }
  69.  
  70. internal class Professor : Person
  71. {
  72. private readonly string _grade;
  73. private readonly int _officeNumber;
  74. private new readonly int year;
  75.  
  76. public Professor( string name, string phone, string email, string grade, int officeNumber, int year)
  77. : base(name, phone, email)
  78. {
  79. _grade = grade;
  80. _officeNumber = officeNumber;
  81. this.year = year;
  82. }
  83.  
  84. public new void personal_info()
  85. {
  86. Console.WriteLine($"직급 : {_grade} 사무실 : {_officeNumber} 근무년수 : {year}");
  87. }
  88. }
  89.  
  90.  
  91. class Program
  92. {
  93. private static int InputChoiceReturnInt()
  94. {
  95. var choice = int.Parse(Console.ReadLine() ?? throw new InvalidOperationException());
  96. return choice;
  97. }
  98.  
  99. private static string InputChoiceReturnString()
  100. {
  101. var inputStr = Console.ReadLine();
  102. return inputStr;
  103. }
  104.  
  105. private static int MainMenu()
  106. {
  107. Console.WriteLine("1.추가 2.현황 출력 3.종료");
  108. return InputChoiceReturnInt();
  109. }
  110.  
  111. private static Student NewStudent(int numIdx)
  112. {
  113. Console.Write("이름: ");
  114. var name = InputChoiceReturnString();
  115. Console.Write("전화번호: ");
  116. var phone = InputChoiceReturnString();
  117. Console.Write("이메일: ");
  118. var email = InputChoiceReturnString();
  119. Console.Write("생년: ");
  120. var year = InputChoiceReturnString();
  121. Console.Write("학번: ");
  122. var number = InputChoiceReturnInt();
  123. Console.Write("학과: ");
  124. var major = InputChoiceReturnString();
  125. Console.Write("학년: ");
  126. var year2 = InputChoiceReturnInt();
  127. Console.Write("장학금: ");
  128. var price = InputChoiceReturnInt();
  129.  
  130. var tempStudent = new Student(name, phone, email, number, major, year2)
  131. {
  132. year = year,
  133. Number = numIdx,
  134. Price = price
  135. };
  136.  
  137. return tempStudent;
  138. }
  139.  
  140. private static Professor NewProfessor(int numIdx)
  141. {
  142. Console.Write("이름: ");
  143. var name = InputChoiceReturnString();
  144. Console.Write("전화번호: ");
  145. var phone = InputChoiceReturnString();
  146. Console.Write("이메일: ");
  147. var email = InputChoiceReturnString();
  148. Console.Write("생년: ");
  149. var year = InputChoiceReturnString();
  150. Console.Write("직급: ");
  151. var grade = InputChoiceReturnString();
  152. Console.Write("사무실: ");
  153. var officeNumber = InputChoiceReturnInt();
  154. Console.Write("근무년수: ");
  155. var year2 = InputChoiceReturnInt();
  156.  
  157. var tempProfessor = new Professor(name, phone, email, grade, officeNumber, year2);
  158.  
  159. ((Person)tempProfessor).year = year;
  160. tempProfessor.Number = numIdx;
  161.  
  162. return tempProfessor;
  163. }
  164.  
  165. public static Person AddProcess(int num)
  166. {
  167. Console.WriteLine("1. 학생 2. 교직원");
  168. var choice = InputChoiceReturnInt();
  169.  
  170. switch (choice)
  171. {
  172. case 1:
  173. var newStudent = NewStudent(num);
  174. return newStudent;
  175. case 2:
  176. var newProfessor = NewProfessor(num);
  177. return newProfessor;
  178. default:
  179. return null;
  180. }
  181. }
  182.  
  183. public static void PerSetting(List<Person> persons)
  184. {
  185. var p0Person = new Person("aaa", "01012345678", "aaa@hnu.ac.kr") {year = "2010", Number = 0};
  186. var p1Student = new Student("bbb", "0102093744", "bbb@hnu.kr", 20120001, "Computer", 1) {Price = 250, Number = 1};
  187. var p2Professor = new Professor("ccc", "01034634690", "ccc@hnu.kr", "Professor", 90100, 20){Number = 2};
  188. var p3Person = new Person("ddd", "01088959078", "ddd@hnu.kr"){Number = 3};
  189. var p4Student = new Student("eee", "01023487909", "eee@hnu.kr", 20136789, "Computer", 3){Price = 0, Number = 4};
  190. var p5Professor = new Professor("ccc", "01086446788", "ttt@hnu.kr", "Professor", 90200, 30) { Number = 5 };
  191. var p6Student = new Student("eee", "0107894563", "eee@hnu.kr", 20130001, "컴퓨터통신무인기술학과", 2){Price = 400, Number = 6};
  192. var p7Professor = new Professor("ggg", "01074125896", "ggg@hnu.kr", "조교수", 90200, 5){Number = 7};
  193.  
  194. persons.Add(p0Person);
  195. persons.Add(p1Student);
  196. persons.Add(p2Professor);
  197. persons.Add(p3Person);
  198. persons.Add(p4Student);
  199. persons.Add(p5Professor);
  200. persons.Add(p6Student);
  201. persons.Add(p7Professor);
  202. }
  203.  
  204. public static void StatusPrint(List<Person> personList)
  205. {
  206. foreach (var person in personList)
  207. {
  208. switch (person)
  209. {
  210. case Professor _:
  211. ((Person)person).personal_info();
  212. ((Professor)person).personal_info();
  213. break;
  214. case Student _:
  215. person.personal_info();
  216. break;
  217. default:
  218. person.personal_info();
  219. Console.WriteLine();
  220. break;
  221. }
  222. }
  223. }
  224.  
  225. private static void Main()
  226. {
  227. var lsPersons = new List<Person>();
  228. PerSetting(lsPersons);
  229.  
  230. while (true)
  231. {
  232. var myChoice = MainMenu();
  233.  
  234. switch (myChoice)
  235. {
  236. case 1:
  237. var newPerson = AddProcess(lsPersons.Count);
  238. lsPersons.Add(newPerson);
  239. break;
  240. case 2:
  241. StatusPrint(lsPersons);
  242. break;
  243. case 3:
  244. Environment.Exit(0);
  245. break;
  246. }
  247.  
  248. Console.WriteLine();
  249. }
  250. }
  251. }
  252. }
Add Comment
Please, Sign In to add comment