Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace PeopleManagement
- {
- class Person
- {
- public int Number;
- public string Name;
- public string Phone, Email, year;
- public Person(string name, string phone, string email)
- {
- Name = name;
- Phone = phone;
- Email = email;
- }
- public Person()
- {
- }
- public virtual void personal_info()
- {
- Console.Write($"순번 : {Number} 이름 : {Name} 전화번호 : {Phone} 이메일 : {Email}");
- }
- }
- class Student : Person
- {
- private readonly int _studentNumber;
- private int _price;
- private new int year; // 학년
- private readonly string _major;
- public Student(string name, string phone, string email, int studentNumber, string major, int year) : base(name, phone, email)
- {
- _studentNumber = studentNumber;
- _major = major;
- this.year = year;
- }
- public Student()
- {
- }
- public int Price
- {
- get => _price;
- set
- {
- if (value > 500)
- {
- Console.WriteLine("최대 수혜 장학금은 500이 넘지 않아야 함");
- }
- else
- {
- _price = value;
- }
- }
- }
- public override void personal_info()
- {
- Console.WriteLine($"순번 : {Number} 이름 : {Name} 전화번호 : {Phone} 이메일 : {Email} 학번 : {_studentNumber} " +
- $"학과 : {_major} 학년 : {year} 장학금 : {Price}");
- }
- }
- internal class Professor : Person
- {
- private readonly string _grade;
- private readonly int _officeNumber;
- private new readonly int year;
- public Professor( string name, string phone, string email, string grade, int officeNumber, int year)
- : base(name, phone, email)
- {
- _grade = grade;
- _officeNumber = officeNumber;
- this.year = year;
- }
- public new void personal_info()
- {
- Console.WriteLine($"직급 : {_grade} 사무실 : {_officeNumber} 근무년수 : {year}");
- }
- }
- class Program
- {
- private static int InputChoiceReturnInt()
- {
- var choice = int.Parse(Console.ReadLine() ?? throw new InvalidOperationException());
- return choice;
- }
- private static string InputChoiceReturnString()
- {
- var inputStr = Console.ReadLine();
- return inputStr;
- }
- private static int MainMenu()
- {
- Console.WriteLine("1.추가 2.현황 출력 3.종료");
- return InputChoiceReturnInt();
- }
- private static Student NewStudent(int numIdx)
- {
- Console.Write("이름: ");
- var name = InputChoiceReturnString();
- Console.Write("전화번호: ");
- var phone = InputChoiceReturnString();
- Console.Write("이메일: ");
- var email = InputChoiceReturnString();
- Console.Write("생년: ");
- var year = InputChoiceReturnString();
- Console.Write("학번: ");
- var number = InputChoiceReturnInt();
- Console.Write("학과: ");
- var major = InputChoiceReturnString();
- Console.Write("학년: ");
- var year2 = InputChoiceReturnInt();
- Console.Write("장학금: ");
- var price = InputChoiceReturnInt();
- var tempStudent = new Student(name, phone, email, number, major, year2)
- {
- year = year,
- Number = numIdx,
- Price = price
- };
- return tempStudent;
- }
- private static Professor NewProfessor(int numIdx)
- {
- Console.Write("이름: ");
- var name = InputChoiceReturnString();
- Console.Write("전화번호: ");
- var phone = InputChoiceReturnString();
- Console.Write("이메일: ");
- var email = InputChoiceReturnString();
- Console.Write("생년: ");
- var year = InputChoiceReturnString();
- Console.Write("직급: ");
- var grade = InputChoiceReturnString();
- Console.Write("사무실: ");
- var officeNumber = InputChoiceReturnInt();
- Console.Write("근무년수: ");
- var year2 = InputChoiceReturnInt();
- var tempProfessor = new Professor(name, phone, email, grade, officeNumber, year2);
- ((Person)tempProfessor).year = year;
- tempProfessor.Number = numIdx;
- return tempProfessor;
- }
- public static Person AddProcess(int num)
- {
- Console.WriteLine("1. 학생 2. 교직원");
- var choice = InputChoiceReturnInt();
- switch (choice)
- {
- case 1:
- var newStudent = NewStudent(num);
- return newStudent;
- case 2:
- var newProfessor = NewProfessor(num);
- return newProfessor;
- default:
- return null;
- }
- }
- public static void PerSetting(List<Person> persons)
- {
- var p0Person = new Person("aaa", "01012345678", "aaa@hnu.ac.kr") {year = "2010", Number = 0};
- var p1Student = new Student("bbb", "0102093744", "bbb@hnu.kr", 20120001, "Computer", 1) {Price = 250, Number = 1};
- var p2Professor = new Professor("ccc", "01034634690", "ccc@hnu.kr", "Professor", 90100, 20){Number = 2};
- var p3Person = new Person("ddd", "01088959078", "ddd@hnu.kr"){Number = 3};
- var p4Student = new Student("eee", "01023487909", "eee@hnu.kr", 20136789, "Computer", 3){Price = 0, Number = 4};
- var p5Professor = new Professor("ccc", "01086446788", "ttt@hnu.kr", "Professor", 90200, 30) { Number = 5 };
- var p6Student = new Student("eee", "0107894563", "eee@hnu.kr", 20130001, "컴퓨터통신무인기술학과", 2){Price = 400, Number = 6};
- var p7Professor = new Professor("ggg", "01074125896", "ggg@hnu.kr", "조교수", 90200, 5){Number = 7};
- persons.Add(p0Person);
- persons.Add(p1Student);
- persons.Add(p2Professor);
- persons.Add(p3Person);
- persons.Add(p4Student);
- persons.Add(p5Professor);
- persons.Add(p6Student);
- persons.Add(p7Professor);
- }
- public static void StatusPrint(List<Person> personList)
- {
- foreach (var person in personList)
- {
- switch (person)
- {
- case Professor _:
- ((Person)person).personal_info();
- ((Professor)person).personal_info();
- break;
- case Student _:
- person.personal_info();
- break;
- default:
- person.personal_info();
- Console.WriteLine();
- break;
- }
- }
- }
- private static void Main()
- {
- var lsPersons = new List<Person>();
- PerSetting(lsPersons);
- while (true)
- {
- var myChoice = MainMenu();
- switch (myChoice)
- {
- case 1:
- var newPerson = AddProcess(lsPersons.Count);
- lsPersons.Add(newPerson);
- break;
- case 2:
- StatusPrint(lsPersons);
- break;
- case 3:
- Environment.Exit(0);
- break;
- }
- Console.WriteLine();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment