Skip to content

Commit

Permalink
Interface Transfer is mark done
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdurahmon0412 committed Aug 9, 2023
1 parent d29ebe5 commit e168ebc
Show file tree
Hide file tree
Showing 11 changed files with 315 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Homeworks.sln
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "N18_1", "N18_1\N18_1.csproj
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "N19", "N19", "{5D0A5ACF-8665-4299-8A8E-D79498D3D059}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N19_1", "N19_1\N19_1.csproj", "{96392CE8-A652-4D1D-BD85-09B29E96B12C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "N19_1", "N19_1\N19_1.csproj", "{96392CE8-A652-4D1D-BD85-09B29E96B12C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N19_2", "N19_2\N19_2.csproj", "{3ED5EB28-7030-4269-9EAF-AC34BC23A51D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "N19_2", "N19_2\N19_2.csproj", "{3ED5EB28-7030-4269-9EAF-AC34BC23A51D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "N21", "N21", "{1B9C8189-61EE-400A-9EF2-5711CDBC0211}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "N21_Interface", "N21_Interface", "{1E3B46C5-6289-417F-94BE-45CE100A96F6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N21_Interface1", "N21_Interface1\N21_Interface1.csproj", "{F26AE334-DB40-46DF-AB84-0D9AD2FE74B5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -301,6 +307,10 @@ Global
{3ED5EB28-7030-4269-9EAF-AC34BC23A51D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3ED5EB28-7030-4269-9EAF-AC34BC23A51D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3ED5EB28-7030-4269-9EAF-AC34BC23A51D}.Release|Any CPU.Build.0 = Release|Any CPU
{F26AE334-DB40-46DF-AB84-0D9AD2FE74B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F26AE334-DB40-46DF-AB84-0D9AD2FE74B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F26AE334-DB40-46DF-AB84-0D9AD2FE74B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F26AE334-DB40-46DF-AB84-0D9AD2FE74B5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -363,6 +373,8 @@ Global
{CDF49DFE-F765-4582-A415-7FCE7BB26FE6} = {2D7CB3B4-5800-4F9D-B995-0989DC4898B7}
{96392CE8-A652-4D1D-BD85-09B29E96B12C} = {5D0A5ACF-8665-4299-8A8E-D79498D3D059}
{3ED5EB28-7030-4269-9EAF-AC34BC23A51D} = {5D0A5ACF-8665-4299-8A8E-D79498D3D059}
{1E3B46C5-6289-417F-94BE-45CE100A96F6} = {1B9C8189-61EE-400A-9EF2-5711CDBC0211}
{F26AE334-DB40-46DF-AB84-0D9AD2FE74B5} = {1E3B46C5-6289-417F-94BE-45CE100A96F6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8B77269B-B20D-4860-9637-2E2771096EE6}
Expand Down
29 changes: 29 additions & 0 deletions N21_Interface1/Cards/KapitalUzcard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using N21_Interface1.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace N21_Interface1.Cards
{
internal class KapitalUzcard : IDebitCard
{
public string CardNumber { get; set; }
public string BankName { get; init; }
public double Balance { get; set; }

public KapitalUzcard(string cardnumber, string bankname, double balance = 0)
{
if (string.IsNullOrWhiteSpace(cardnumber))
throw new ArgumentException("Invalid card number");
if (string.IsNullOrWhiteSpace(bankname))
throw new ArgumentException("Invalid Bank name");
if (balance < 0)
throw new ArgumentException("Balanced not used ");
CardNumber = cardnumber;
BankName = bankname;
Balance = balance;
}
}
}
29 changes: 29 additions & 0 deletions N21_Interface1/Cards/MilliyHumo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using N21_Interface1.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace N21_Interface1.Cards
{
internal class MilliyHumo : IDebitCard
{
public string CardNumber { get; set; }
public string BankName { get; init; }
public double Balance { get; set; }

public MilliyHumo(string cardnumber, string bankname,double balance = 0)
{
if (cardnumber.Length < 16 || string.IsNullOrWhiteSpace(cardnumber))
throw new ArgumentException("Invalid card number");
if (string.IsNullOrWhiteSpace(bankname))
throw new ArgumentException("Invalid Bank name");
if (balance < 0)
throw new ArgumentException("Balanced not used ");
CardNumber = cardnumber;
BankName = bankname;
Balance = balance;
}
}
}
17 changes: 17 additions & 0 deletions N21_Interface1/Interfaces/IDebitCard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace N21_Interface1.Interfaces
{
public interface IDebitCard
{
public string CardNumber { get; set; }
public string BankName { get; init; }
public double Balance { get; set; }


}
}
16 changes: 16 additions & 0 deletions N21_Interface1/Interfaces/IPaymentProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace N21_Interface1.Interfaces
{
public interface IPaymentProvider
{
public double TransferInterest { get; init; }
public bool Transfer(IDebitCard sourcecard, IDebitCard destinationcard, in double amount) { return false; }


}
}
10 changes: 10 additions & 0 deletions N21_Interface1/N21_Interface1.csproj
Original file line number Diff line number Diff line change
@@ -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>
56 changes: 56 additions & 0 deletions N21_Interface1/OnlineMarket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using N21_Interface1.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Runtime.InteropServices.JavaScript.JSType;
using System.Xml.Linq;
using N21_Interface1.Cards;
namespace N21_Interface1
{
public class OnlineMarket
{
private IDebitCard BankAccount = new KapitalUzcard("OnlaynBankCard", "Hamkorbank", 0);
private readonly IPaymentProvider _paymentProvider;
private readonly List<Product> _products;
public OnlineMarket(IPaymentProvider paymentProvider)
{

_paymentProvider = paymentProvider;
_products = new List<Product>();

}

public void Add(Product product)
{
_products.Add(product);
}
//Buy(name, number, card ) - product lar ichidan berilgan nomdagi produktni berilgan sonda hisoblab,
// kartadan pul yechishni payment provider orqali amalga oshirsin
public void Buy(string name, int number, IDebitCard card)
{
foreach (Product product in _products)
{
if(product.Name.Equals(name, StringComparison.OrdinalIgnoreCase))
{
try
{
if(_paymentProvider.Transfer( card, BankAccount, product.Price * number))
{
Console.WriteLine("harid muvaffaqiyatli amalga oshirildi");
}
else { throw new ArgumentNullException("Mahsulot sotib olish uchun yetarli mablag' mavjud emas"); }

}
catch(ArgumentNullException arg)
{
Console.WriteLine(arg.Message);
}

}
}
}

}
}
22 changes: 22 additions & 0 deletions N21_Interface1/Product.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace N21_Interface1
{
public class Product
{
public string Name { get; set; }
public double Price { get; set; }

public Product(string name, double price)
{
if(!string.IsNullOrWhiteSpace( name))
Name = name;
if(price > 0)
Price = price;
}
}
}
52 changes: 52 additions & 0 deletions N21_Interface1/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

//dasturda o'zingiz xohlagan payment provider ( KapitalUzcard, MillyHumo ) dan instance ( object ) yarating
//- OnlineMarket dan o'sha provider bilan instance yarating
//- Product dam bir nechta instance yarating va OnlineMarket ga qo'shing
//- o'zingiz xohlagan kartadan ( KapitalUzcard yoki MillyHumo ) instance yarating
//- bir nechta produktlarni sotib olish operatsiyasini OnlineMarket orqali bajaring
//- kartada qolgan summani ekranga chiqaring


using N21_Interface1;
using N21_Interface1.Cards;
using N21_Interface1.Interfaces;
using N21_Interface1.Providers;

IPaymentProvider Payme = new PaymePaymentProvider();
//IPaymentProvider Uzum = new UzumPaymentProvider();



var OnlaynMarket1 = new OnlineMarket(Payme);
//var OnlaynMarket2 = new OnlineMarket(Uzum);
Product product1 = new Product("Cola", 1000);
Product product2 = new Product("Pepsi", 1200);
Product product3 = new Product("Qurt", 500);
Product product4 = new Product("zizi", 5000);
Product product5 = new Product("Parashok", 14000);

OnlaynMarket1.Add(product1);
OnlaynMarket1.Add(product2);
OnlaynMarket1.Add(product3);
OnlaynMarket1.Add(product4);
OnlaynMarket1.Add(product5);

IDebitCard uzcard = new KapitalUzcard("12234567890123654", "Hamkorbank", 2000000);
IDebitCard humo = new MilliyHumo("11111211111111111", "Agrobank", 5000000);

OnlaynMarket1.Buy("Cola", 3, uzcard);
Console.WriteLine($"Kartadagi mablag': " + uzcard.Balance);
OnlaynMarket1.Buy("zizi", 3, uzcard);
Console.WriteLine($"Kartadagi mablag': " + uzcard.Balance);
OnlaynMarket1.Buy("parashok", 3, uzcard);
Console.WriteLine($"Kartadagi mablag': " + uzcard.Balance);
OnlaynMarket1.Buy("qurt", 3, uzcard);









35 changes: 35 additions & 0 deletions N21_Interface1/Providers/PaymePaymentProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using N21_Interface1.Interfaces;

namespace N21_Interface1.Providers
{
public class PaymePaymentProvider : IPaymentProvider
{
public double TransferInterest { get; init; }


public PaymePaymentProvider(double transferinterest = 1)
{
TransferInterest = transferinterest;
}


public bool Transfer(IDebitCard sourcecard, IDebitCard destinationcard, in double amount)
{
if (amount <= 0 || sourcecard.Balance < amount + (amount / 100 * TransferInterest) || sourcecard.Balance <= 0)
{
return false;
}
else
{
sourcecard.Balance -= amount + (amount / 100 * TransferInterest);
destinationcard.Balance += amount;
return true;
}
}
}
}
35 changes: 35 additions & 0 deletions N21_Interface1/Providers/UzumPaymentProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using N21_Interface1.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace N21_Interface1.Providers
{
public class UzumPaymentProvider : IPaymentProvider
{
public double TransferInterest { get; init; }


public UzumPaymentProvider(double transferinterest = 0.5)
{
TransferInterest = transferinterest;
}


public bool Transfer(IDebitCard sourcecard, IDebitCard destinationcard, in double amount)
{
if(amount <= 0 || sourcecard.Balance < amount + (amount / 100 * TransferInterest) || sourcecard.Balance <= 0)
{
return false;
}
else
{
sourcecard.Balance -= amount + (amount / 100 * TransferInterest);
destinationcard.Balance += amount;
return true;
}
}
}
}

0 comments on commit e168ebc

Please sign in to comment.