-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d29ebe5
commit e168ebc
Showing
11 changed files
with
315 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |