Add Lesson 4 Tasks 1 and 2

This commit is contained in:
Stanislav Mykhailenko 2023-04-03 17:11:06 +03:00
parent e8596ca709
commit db251c4838
GPG key ID: 1E95E66A9C9D6A36
7 changed files with 120 additions and 0 deletions

View 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();
}
}
}
}

View file

@ -0,0 +1,2 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

View 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>

View 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...");
}
}
}

View file

@ -0,0 +1,2 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

View 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>

View file

@ -24,3 +24,8 @@ Checked means the task is Done.
### Lesson 3
- [x] Task 1
### Lesson 4
- [ ] Task 1
- [ ] Task 2