Move classes to separate files

This commit is contained in:
Stanislav Mykhailenko 2023-03-20 02:14:49 +02:00
parent c7cb2e8fd9
commit 9e9b668423
GPG key ID: 1E95E66A9C9D6A36
9 changed files with 98 additions and 85 deletions

View file

@ -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;
}
}

View file

@ -4,6 +4,8 @@
* License: Unlicense * License: Unlicense
*/ */
using ProductClass;
List<Product> products = new List<Product>(); List<Product> products = new List<Product>();
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
@ -42,21 +44,3 @@ for (int i = 0; i < 2; i++)
Console.WriteLine(product); 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;
}
}

18
Lesson_2/Task_2/Person.cs Normal file
View file

@ -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;
}
}

View file

@ -4,6 +4,8 @@
* License: Unlicense * License: Unlicense
*/ */
using PersonClass;
List<Person> people = new List<Person>() List<Person> people = new List<Person>()
{ {
new Person("Tom",18), new Person("Tom",18),
@ -36,20 +38,3 @@ foreach (Person person in selected)
{ {
Console.WriteLine(person); 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;
}
}

View file

@ -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;
}
}

View file

@ -4,6 +4,8 @@
* License: Unlicense * License: Unlicense
*/ */
using CustomerClass;
List<Customer> customers = new List<Customer>() List<Customer> customers = new List<Customer>()
{ {
new Customer("Tom", 14, "Street 1"), new Customer("Tom", 14, "Street 1"),
@ -38,22 +40,3 @@ foreach (Customer customer in selected)
var number = selected.Where(customer => customer.Age >= 18).Count(); var number = selected.Where(customer => customer.Age >= 18).Count();
Console.WriteLine("Amount of customers older than 18: " + number); 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;
}
}

13
Lesson_2/Task_4/Car.cs Normal file
View file

@ -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;
}
}

20
Lesson_2/Task_4/Owner.cs Normal file
View file

@ -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;
}
}

View file

@ -4,6 +4,9 @@
* License: Unlicense * License: Unlicense
*/ */
using CarClass;
using OwnerClass;
List<Owner> owners = new List<Owner>() List<Owner> owners = new List<Owner>()
{ {
new Owner(1, "Tom", "Street 1"), 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)); var selected = owners.FirstOrDefault(owner => cars.Any(car => car.Number == number && car.OwnerId == owner.Id));
Console.WriteLine(selected); 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;
}
}