Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace LV7___Zadatak_1
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<IPayable> list = new List<IPayable>();
- BankAccount B1 = new BankAccount("Enio", 1000, 0.0);
- BankAccount B2 = new BankAccount("Petar", 2000, 500);
- MobileAccount P1 = new MobileAccount("0992051444", 2.5, 50);
- MobileAccount P2 = new MobileAccount("0976432454", 1.4, 100);
- list.Add(B1);
- list.Add(B2);
- list.Add(P1);
- list.Add(P2);
- Random rnd = new Random();
- foreach (IPayable account in list)
- {
- account.SendPayment(rnd.Next(10, 100));
- }
- foreach (IPayable account in list)
- {
- account.RequestPayment(rnd.Next(1, 100));
- }
- foreach (IPayable account in list)
- {
- Console.WriteLine("Balance: " + account.GetBalance() + "$");
- }
- }
- }
- interface IPayable
- {
- double GetBalance();
- void SendPayment(double payment);
- void RequestPayment(double payment);
- }
- public class BankAccount : IPayable
- {
- private string mName;
- private double mLimit;
- private double mBalance;
- public BankAccount(string name, double limit, double balance)
- {
- this.mName = name;
- this.mLimit = limit;
- this.mBalance = balance;
- }
- public double GetBalance()
- {
- return this.mBalance;
- }
- public void SendPayment(double payment)
- {
- this.mBalance += payment;
- }
- public void RequestPayment(double payment)
- {
- double balance = this.mBalance;
- balance -= payment;
- if (balance > mLimit)
- {
- this.mBalance += payment;
- }
- else
- {
- Console.WriteLine("Error!");
- }
- }
- }
- public class MobileAccount : IPayable
- {
- private string mNumber;
- private double mPrice;
- private double mBalance;
- public MobileAccount(string number, double price, double balance)
- {
- this.mNumber = number;
- this.mPrice = price;
- this.mBalance = balance;
- }
- public double GetBalance()
- {
- return this.mBalance;
- }
- public void SendPayment(double payment)
- {
- this.mBalance += payment;
- }
- public void RequestPayment(double payment)
- {
- double balance = this.mBalance;
- balance -= payment;
- if (balance > 0)
- {
- this.mBalance += payment;
- }
- else
- {
- Console.WriteLine("Error!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement