Move classes to separate files
This commit is contained in:
parent
c7cb2e8fd9
commit
9e9b668423
9 changed files with 98 additions and 85 deletions
18
Lesson_2/Task_1/Product.cs
Normal file
18
Lesson_2/Task_1/Product.cs
Normal 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;
|
||||
}
|
||||
}
|
|
@ -4,6 +4,8 @@
|
|||
* License: Unlicense
|
||||
*/
|
||||
|
||||
using ProductClass;
|
||||
|
||||
List<Product> products = new List<Product>();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
18
Lesson_2/Task_2/Person.cs
Normal file
18
Lesson_2/Task_2/Person.cs
Normal 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;
|
||||
}
|
||||
}
|
|
@ -4,6 +4,8 @@
|
|||
* License: Unlicense
|
||||
*/
|
||||
|
||||
using PersonClass;
|
||||
|
||||
List<Person> people = new List<Person>()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
20
Lesson_2/Task_3/Customer.cs
Normal file
20
Lesson_2/Task_3/Customer.cs
Normal 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;
|
||||
}
|
||||
}
|
|
@ -4,6 +4,8 @@
|
|||
* License: Unlicense
|
||||
*/
|
||||
|
||||
using CustomerClass;
|
||||
|
||||
List<Customer> customers = new List<Customer>()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
13
Lesson_2/Task_4/Car.cs
Normal file
13
Lesson_2/Task_4/Car.cs
Normal 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
20
Lesson_2/Task_4/Owner.cs
Normal 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;
|
||||
}
|
||||
}
|
|
@ -4,6 +4,9 @@
|
|||
* License: Unlicense
|
||||
*/
|
||||
|
||||
using CarClass;
|
||||
using OwnerClass;
|
||||
|
||||
List<Owner> owners = new List<Owner>()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue