From 9e9b66842369efa5ac46ae882ae8406a79dd55fd Mon Sep 17 00:00:00 2001 From: Stanislav Mykhailenko Date: Mon, 20 Mar 2023 02:14:49 +0200 Subject: [PATCH] Move classes to separate files --- Lesson_2/Task_1/Product.cs | 18 ++++++++++++++++++ Lesson_2/Task_1/Program.cs | 20 ++------------------ Lesson_2/Task_2/Person.cs | 18 ++++++++++++++++++ Lesson_2/Task_2/Program.cs | 19 ++----------------- Lesson_2/Task_3/Customer.cs | 20 ++++++++++++++++++++ Lesson_2/Task_3/Program.cs | 21 ++------------------- Lesson_2/Task_4/Car.cs | 13 +++++++++++++ Lesson_2/Task_4/Owner.cs | 20 ++++++++++++++++++++ Lesson_2/Task_4/Program.cs | 34 +++------------------------------- 9 files changed, 98 insertions(+), 85 deletions(-) create mode 100644 Lesson_2/Task_1/Product.cs create mode 100644 Lesson_2/Task_2/Person.cs create mode 100644 Lesson_2/Task_3/Customer.cs create mode 100644 Lesson_2/Task_4/Car.cs create mode 100644 Lesson_2/Task_4/Owner.cs diff --git a/Lesson_2/Task_1/Product.cs b/Lesson_2/Task_1/Product.cs new file mode 100644 index 0000000..4a6229a --- /dev/null +++ b/Lesson_2/Task_1/Product.cs @@ -0,0 +1,18 @@ +namespace ProductClass; + +class Product +{ + public string Name { get;} + public float Price { get;} + + public override string ToString() + { + return "Name: " + Name + ", Price: " + Price; + } + + public Product(string name, float price) + { + Name = name; + Price = price; + } +} diff --git a/Lesson_2/Task_1/Program.cs b/Lesson_2/Task_1/Program.cs index 2485395..c548bb6 100644 --- a/Lesson_2/Task_1/Program.cs +++ b/Lesson_2/Task_1/Program.cs @@ -4,6 +4,8 @@ * License: Unlicense */ +using ProductClass; + List products = new List(); for (int i = 0; i < 10; i++) @@ -42,21 +44,3 @@ for (int i = 0; i < 2; i++) Console.WriteLine(product); } } - -class Product -{ - public string Name { get;} - public float Price { get;} - - public override string ToString() - { - return "Name: " + Name + ", Price: " + Price; - } - - public Product(string name, float price) - { - Name = name; - Price = price; - } -} - diff --git a/Lesson_2/Task_2/Person.cs b/Lesson_2/Task_2/Person.cs new file mode 100644 index 0000000..04e1cb3 --- /dev/null +++ b/Lesson_2/Task_2/Person.cs @@ -0,0 +1,18 @@ +namespace PersonClass; + +class Person +{ + public string Name { get;} + public int Age { get;} + + public override string ToString() + { + return "Name: " + Name + ", Age: " + Age; + } + + public Person(string name, int age) + { + Name = name; + Age = age; + } +} diff --git a/Lesson_2/Task_2/Program.cs b/Lesson_2/Task_2/Program.cs index e820d30..febdcbc 100644 --- a/Lesson_2/Task_2/Program.cs +++ b/Lesson_2/Task_2/Program.cs @@ -4,6 +4,8 @@ * License: Unlicense */ +using PersonClass; + List people = new List() { new Person("Tom",18), @@ -36,20 +38,3 @@ foreach (Person person in selected) { Console.WriteLine(person); } - -class Person -{ - public string Name { get;} - public int Age { get;} - - public override string ToString() - { - return "Name: " + Name + ", Age: " + Age; - } - - public Person(string name, int age) - { - Name = name; - Age = age; - } -} diff --git a/Lesson_2/Task_3/Customer.cs b/Lesson_2/Task_3/Customer.cs new file mode 100644 index 0000000..1020b13 --- /dev/null +++ b/Lesson_2/Task_3/Customer.cs @@ -0,0 +1,20 @@ +namespace CustomerClass; + +class Customer +{ + public string Name { get;} + public int Age { get;} + public string Address { get;} + + public override string ToString() + { + return "Name: " + Name + ", Age: " + Age + ", Address: " + Address; + } + + public Customer(string name, int age, string address) + { + Name = name; + Age = age; + Address = address; + } +} \ No newline at end of file diff --git a/Lesson_2/Task_3/Program.cs b/Lesson_2/Task_3/Program.cs index 20a353a..00715a8 100644 --- a/Lesson_2/Task_3/Program.cs +++ b/Lesson_2/Task_3/Program.cs @@ -4,6 +4,8 @@ * License: Unlicense */ +using CustomerClass; + List customers = new List() { new Customer("Tom", 14, "Street 1"), @@ -38,22 +40,3 @@ foreach (Customer customer in selected) var number = selected.Where(customer => customer.Age >= 18).Count(); Console.WriteLine("Amount of customers older than 18: " + number); - -class Customer -{ - public string Name { get;} - public int Age { get;} - public string Address { get;} - - public override string ToString() - { - return "Name: " + Name + ", Age: " + Age + ", Address: " + Address; - } - - public Customer(string name, int age, string address) - { - Name = name; - Age = age; - Address = address; - } -} diff --git a/Lesson_2/Task_4/Car.cs b/Lesson_2/Task_4/Car.cs new file mode 100644 index 0000000..abc1a6a --- /dev/null +++ b/Lesson_2/Task_4/Car.cs @@ -0,0 +1,13 @@ +namespace CarClass; + +class Car +{ + public string Number { get;} + public int OwnerId { get;} + + public Car(string number, int ownerId) + { + Number = number; + OwnerId = ownerId; + } +} diff --git a/Lesson_2/Task_4/Owner.cs b/Lesson_2/Task_4/Owner.cs new file mode 100644 index 0000000..90db588 --- /dev/null +++ b/Lesson_2/Task_4/Owner.cs @@ -0,0 +1,20 @@ +namespace OwnerClass; + +class Owner +{ + public int Id { get;} + public string Name { get;} + public string Address { get;} + + public override string ToString() + { + return "Name: " + Name + ", Address: " + Address; + } + + public Owner(int id, string name, string address) + { + Id = id; + Name = name; + Address = address; + } +} diff --git a/Lesson_2/Task_4/Program.cs b/Lesson_2/Task_4/Program.cs index 0825052..b7a9489 100644 --- a/Lesson_2/Task_4/Program.cs +++ b/Lesson_2/Task_4/Program.cs @@ -4,6 +4,9 @@ * License: Unlicense */ +using CarClass; +using OwnerClass; + List owners = new List() { new Owner(1, "Tom", "Street 1"), @@ -31,34 +34,3 @@ while (true) var selected = owners.FirstOrDefault(owner => cars.Any(car => car.Number == number && car.OwnerId == owner.Id)); Console.WriteLine(selected); - -class Owner -{ - public int Id { get;} - public string Name { get;} - public string Address { get;} - - public override string ToString() - { - return "Name: " + Name + ", Address: " + Address; - } - - public Owner(int id, string name, string address) - { - Id = id; - Name = name; - Address = address; - } -} - -class Car -{ - public string Number { get;} - public int OwnerId { get;} - - public Car(string number, int ownerId) - { - Number = number; - OwnerId = ownerId; - } -}