Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<Student> students_list = new List<Student>();
- Console.WriteLine("1. Создание студента\n2. Вывести всех студентов\n3. Сравнение студентов\n");
- while (true)
- {
- try
- {
- switch (Console.ReadLine())
- {
- case "1":
- Builder1 builder1 = new Builder1();
- Director director = new Director(builder1);
- director.MakeFullDefaultStudent();
- Student student = builder1.GetStudent();
- Console.WriteLine("Введите имя");
- student.Name = Console.ReadLine();
- Console.WriteLine("Введите пол \n1. М\n2. Ж");
- if(Console.ReadLine() == "2")
- {
- student.Gender = "Ж";
- }
- Console.WriteLine("Введите форму обучения\n1. Очная\n2. Заочная");
- if (Console.ReadLine() == "2")
- {
- student.Education = "Заочная";
- }
- Console.WriteLine("Семейное положение\n1. Не женат(не замужем)\n2. Женат(за мужем)");
- if (Console.ReadLine() == "2")
- {
- student.Married = "Женат(Замужем)";
- }
- Console.WriteLine("1. Работает\n2. Не работает");
- if (Console.ReadLine() == "2")
- {
- student.Employment = "Не работает";
- }
- Console.WriteLine("Есть дети?\n1. Нет детей\n2. Да");
- if(Console.ReadLine() == "2")
- {
- Console.WriteLine("Введите количество детей");
- int count = Convert.ToInt32(Console.ReadLine());
- for (int i = 0; i < count; i++)
- {
- Child child = new();
- Console.WriteLine("Введите имя ребенка");
- child.Name = Console.ReadLine();
- Console.WriteLine("Введите пол \n1. М\n2. Ж");
- if (Console.ReadLine() == "1")
- {
- child.Gender = "М";
- }
- else
- {
- child.Gender = "Ж";
- }
- Console.WriteLine("Введите дату рождения (прим. 01.01.2000)");
- child.Birthday = Console.ReadLine();
- Console.WriteLine("Введите увлечение");
- child.Hobbies = Console.ReadLine();
- student.children.Add(child);
- }
- }
- students_list.Add(student);
- break;
- case "2":
- foreach (Student item in students_list)
- {
- Console.WriteLine("=======================");
- Console.WriteLine("Студент №" + students_list.IndexOf(item));
- item.GetInfo();
- }
- break;
- case "3":
- Console.WriteLine("Введите первого студента");
- Student st1 = students_list[Convert.ToInt32(Console.ReadLine())];
- Console.WriteLine("Введите второго студента");
- Student st2 = students_list[Convert.ToInt32(Console.ReadLine())];
- Compars(st1,st2);
- break;
- }
- }
- catch (Exception e)
- {
- Console.WriteLine("Ошибка!");
- Console.WriteLine(e.Message);
- }
- }
- }
- static void Compars(Student student1, Student student2)
- {
- if (student1.Name == student2.Name && student1.Gender == student2.Gender && student1.Education == student2.Education && student1.Married == student2.Married && student1.Employment == student2.Employment && student1.children.Count == student2.children.Count)
- {
- if (student1.children.Count > 0)
- {
- for (int i = 0; i < student1.children.Count; i++)
- {
- if (student1.children[i].Name != student2.children[i].Name || student1.children[i].Gender != student2.children[i].Gender || student1.children[i].Birthday != student2.children[i].Birthday || student1.children[i].Hobbies != student2.children[i].Hobbies)
- {
- Console.WriteLine("Студенты не одинаковы");
- break;
- }
- else
- {
- Console.WriteLine("Студенты одинаковы");
- }
- }
- }
- else
- {
- Console.WriteLine("Студенты одинаковы");
- }
- }
- else
- {
- Console.WriteLine("Студенты не одинаковы");
- }
- }
- }
- }
- class Child
- {
- // Имя
- private string name;
- public string Name { get { return name; } set { name = value; } }
- // Пол
- private string gender;
- public string Gender { get { return gender; } set { gender = value; } }
- // День рождения
- private string birthday;
- public string Birthday { get { return birthday; } set { birthday = value; } }
- // Увлечения
- private string hobbies;
- public string Hobbies { get { return hobbies; } set { hobbies = value; } }
- public void GetInfo()
- {
- Console.WriteLine(Name + "\n" + Gender + "\n" + Birthday + "\n" + Hobbies);
- }
- }
- class Student
- {
- // Имя
- private string name;
- public string Name { get { return name; } set { name = value; } }
- // Пол
- private string gender;
- public string Gender { get { return gender; } set { gender = value; } }
- // Форма обучения
- private string education;
- public string Education { get { return education; } set { education = value; } }
- // Семейное положение
- private string married;
- public string Married { get { return married; } set { married = value; } }
- // Работа
- private string employment;
- public string Employment { get { return employment; } set { employment = value; } }
- public List<Child> children = new List<Child>();
- public void GetInfo()
- {
- Console.WriteLine("Имя: " + Name + "\n" + "Пол: " +Gender + "\n" + "Тип обучения: " + Education + "\n" + "Женат/За мужем?: " + Married + "\n" + "Работает?: " + Employment + "\nДети:\n");
- if (this.children.Count > 0 )
- {
- for (int i = 0; i < this.children.Count; i++)
- {
- int num_of_children = i + 1;
- Console.WriteLine("Ребенок №" + num_of_children);
- this.children[i].GetInfo();
- }
- }
- else
- {
- Console.WriteLine("Детей нет");
- }
- }
- }
- abstract class StudentBuilder
- {
- public abstract void SetName();
- public abstract void SetGender();
- public abstract void SetEducation();
- public abstract void SetMarried();
- public abstract void SetEmployment();
- public abstract void SetChildren();
- }
- class Builder1 : StudentBuilder
- {
- private Student _student = new Student();
- public void Reset()
- {
- this._student = new Student();
- }
- public override void SetName()
- {
- this._student.Name = "#Имя#";
- }
- public override void SetGender()
- {
- this._student.Gender = "М";
- }
- public override void SetEducation()
- {
- this._student.Education = "Очная";
- }
- public override void SetMarried()
- {
- this._student.Married = "Не женат / Не замужем";
- }
- public override void SetEmployment()
- {
- this._student.Employment = "Не работает";
- }
- public override void SetChildren()
- {
- this._student.children.Add(new Child());
- }
- public Student GetStudent()
- {
- Student result = this._student;
- return result;
- }
- }
- class Director
- {
- public StudentBuilder builder;
- public Director(StudentBuilder builder)
- {
- this.builder = builder;
- }
- public void MakeFullDefaultStudent()
- {
- this.builder.SetName();
- this.builder.SetGender();
- this.builder.SetEducation();
- this.builder.SetMarried();
- this.builder.SetEmployment();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement