From db251c48380a6d1a9f0b4245c57cc4611087072c Mon Sep 17 00:00:00 2001 From: Stanislav Mykhailenko Date: Mon, 3 Apr 2023 17:11:06 +0300 Subject: [PATCH] Add Lesson 4 Tasks 1 and 2 --- Lesson_4/Task_1/Customer.cs | 59 +++++++++++++++++++++++++++++++++++ Lesson_4/Task_1/Program.cs | 2 ++ Lesson_4/Task_1/Task_1.csproj | 10 ++++++ Lesson_4/Task_2/MagicClass.cs | 32 +++++++++++++++++++ Lesson_4/Task_2/Program.cs | 2 ++ Lesson_4/Task_2/Task_2.csproj | 10 ++++++ README.md | 5 +++ 7 files changed, 120 insertions(+) create mode 100644 Lesson_4/Task_1/Customer.cs create mode 100644 Lesson_4/Task_1/Program.cs create mode 100644 Lesson_4/Task_1/Task_1.csproj create mode 100644 Lesson_4/Task_2/MagicClass.cs create mode 100644 Lesson_4/Task_2/Program.cs create mode 100644 Lesson_4/Task_2/Task_2.csproj diff --git a/Lesson_4/Task_1/Customer.cs b/Lesson_4/Task_1/Customer.cs new file mode 100644 index 0000000..2ff3015 --- /dev/null +++ b/Lesson_4/Task_1/Customer.cs @@ -0,0 +1,59 @@ +namespace SingleResponsibility +{ + public class Customer + { + public int Id { get; set; } + public string Name { get; set; } + public decimal Balance { get; set; } + + public Customer(int id, string name, decimal balance) + { + Id = id; + Name = name; + Balance = balance; + } + + public void GetBalance() + { + Console.WriteLine($"Your balance is: {Balance}"); + } + } + + public class CustomerList + { + public List Customers = new List() + { + new Customer(1, "Fikus", 0), + new Customer(2, "VHarbar", 100000) + }; + + public decimal? GetBalanceById(int id) + { + var customer = Customers.FirstOrDefault(x => x.Id == id); + if (customer != null) + return customer.Balance; + else + return null; + } + + public Customer? GetById(int id) + { + return Customers.FirstOrDefault(x => x.Id == id); + } + + public void SaveToDatabase() + { + Console.WriteLine("Saved!"); + } + + public void UpdateBalance(int id, decimal newBalance) + { + var customer = GetById(id); + if (customer != null) + { + customer.Balance = newBalance; + SaveToDatabase(); + } + } + } +} diff --git a/Lesson_4/Task_1/Program.cs b/Lesson_4/Task_1/Program.cs new file mode 100644 index 0000000..3751555 --- /dev/null +++ b/Lesson_4/Task_1/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); diff --git a/Lesson_4/Task_1/Task_1.csproj b/Lesson_4/Task_1/Task_1.csproj new file mode 100644 index 0000000..f02677b --- /dev/null +++ b/Lesson_4/Task_1/Task_1.csproj @@ -0,0 +1,10 @@ + + + + Exe + net7.0 + enable + enable + + + diff --git a/Lesson_4/Task_2/MagicClass.cs b/Lesson_4/Task_2/MagicClass.cs new file mode 100644 index 0000000..84b4728 --- /dev/null +++ b/Lesson_4/Task_2/MagicClass.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Open_Closed +{ + public class FireMagic : Magic + { + public override void CountYourMagic() + { + Console.WriteLine("Wow, your magic is fire magic!"); + } + } + + public class WaterMagic : Magic + { + public override void CountYourMagic() + { + Console.WriteLine("Incredible! You have 50 millions of power! It's water magic!"); + } + } + + public class Magic + { + public virtual void CountYourMagic() + { + Console.WriteLine("I understand you..."); + } + } +} diff --git a/Lesson_4/Task_2/Program.cs b/Lesson_4/Task_2/Program.cs new file mode 100644 index 0000000..3751555 --- /dev/null +++ b/Lesson_4/Task_2/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); diff --git a/Lesson_4/Task_2/Task_2.csproj b/Lesson_4/Task_2/Task_2.csproj new file mode 100644 index 0000000..f02677b --- /dev/null +++ b/Lesson_4/Task_2/Task_2.csproj @@ -0,0 +1,10 @@ + + + + Exe + net7.0 + enable + enable + + + diff --git a/README.md b/README.md index e5a7c80..34d24f7 100644 --- a/README.md +++ b/README.md @@ -24,3 +24,8 @@ Checked means the task is Done. ### Lesson 3 - [x] Task 1 + +### Lesson 4 + +- [ ] Task 1 +- [ ] Task 2