Add Lesson 4 Tasks 1 and 2
This commit is contained in:
parent
e8596ca709
commit
db251c4838
7 changed files with 120 additions and 0 deletions
59
Lesson_4/Task_1/Customer.cs
Normal file
59
Lesson_4/Task_1/Customer.cs
Normal file
|
@ -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<Customer> Customers = new List<Customer>()
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
2
Lesson_4/Task_1/Program.cs
Normal file
2
Lesson_4/Task_1/Program.cs
Normal file
|
@ -0,0 +1,2 @@
|
|||
// See https://aka.ms/new-console-template for more information
|
||||
Console.WriteLine("Hello, World!");
|
10
Lesson_4/Task_1/Task_1.csproj
Normal file
10
Lesson_4/Task_1/Task_1.csproj
Normal file
|
@ -0,0 +1,10 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
32
Lesson_4/Task_2/MagicClass.cs
Normal file
32
Lesson_4/Task_2/MagicClass.cs
Normal file
|
@ -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...");
|
||||
}
|
||||
}
|
||||
}
|
2
Lesson_4/Task_2/Program.cs
Normal file
2
Lesson_4/Task_2/Program.cs
Normal file
|
@ -0,0 +1,2 @@
|
|||
// See https://aka.ms/new-console-template for more information
|
||||
Console.WriteLine("Hello, World!");
|
10
Lesson_4/Task_2/Task_2.csproj
Normal file
10
Lesson_4/Task_2/Task_2.csproj
Normal file
|
@ -0,0 +1,10 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
|
@ -24,3 +24,8 @@ Checked means the task is Done.
|
|||
### Lesson 3
|
||||
|
||||
- [x] Task 1
|
||||
|
||||
### Lesson 4
|
||||
|
||||
- [ ] Task 1
|
||||
- [ ] Task 2
|
||||
|
|
Reference in a new issue