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 lr3
- {
- public class Account
- {
- public string Number { get; private set; }
- public double Balance { get; private set; }
- public List<string> History { get; private set; }
- public Account(string num) { this.Number = num; this.Balance = 0; this.History = new List<string>(); }
- public void Add(double money)
- {
- this.Balance += money;
- this.History.Add("+ " + money.ToString());
- }
- public void Withdraw(double money)
- {
- Balance -= money;
- History.Add("- " + money.ToString());
- }
- public void ShowBalance()
- {
- Console.WriteLine(Balance);
- }
- public void ShowHistory()
- {
- Console.WriteLine($"Transaction history of account {Number}:");
- foreach (string transaction in History)
- {
- Console.WriteLine(transaction);
- }
- }
- }
- public class Client
- {
- public string FullName { get; private set; }
- public int Age { get; private set; }
- public string Job { get; private set; }
- private List<Account> Accounts { get; set; }
- public Client(string name, int age, string job)
- {
- this.FullName = name;
- this.Age = age;
- this.Job = job;
- this.Accounts = new List<Account>();
- }
- public void OpenAccount(string number)
- {
- Accounts.Add(new Account(number));
- }
- public void CloseAccount(string number)
- {
- for (int i = 0; i < Accounts.Count; ++i)
- {
- if (Accounts[i].Number == number)
- {
- Accounts.RemoveAt(i);
- }
- }
- }
- public void Transaction(string account, char mode, double money)
- {
- for (int i = 0; i < Accounts.Count; ++i)
- {
- if (Accounts[i].Number == account)
- {
- if (mode == '+') Accounts[i].Add(money);
- else if (mode == '-') Accounts[i].Withdraw(money);
- break;
- }
- }
- }
- public void ShowAccountHistory(string number)
- {
- for (int i = 0; i < Accounts.Count; ++i)
- {
- if (Accounts[i].Number == number)
- {
- Console.WriteLine($"Account {number} history:");
- Accounts[i].ShowHistory();
- }
- }
- }
- public void ShowAllAccounts()
- {
- Console.WriteLine($"All bank accounts of {this.FullName}: ");
- foreach (Account acc in Accounts)
- {
- Console.WriteLine($"Account {acc.Number} balance: {acc.Balance}");
- }
- }
- public void ShowClientInfo()
- {
- Console.WriteLine($"Public user info:\nFull name: {this.FullName}\nAge: {this.Age}\nJob: {this.Job}");
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Creating new user...");
- Client testClient = new Client("Saveliy Savvovich Tvorozhochkin", 228, "Dungeon");
- testClient.ShowClientInfo();
- Console.WriteLine($"\nOpening some accounts for {testClient.FullName}...");
- testClient.OpenAccount("22813371488");
- testClient.OpenAccount("00000000000");
- testClient.OpenAccount("12345678910");
- testClient.ShowAllAccounts();
- Console.WriteLine("\nSome test transactions coming...\n");
- testClient.Transaction("22813371488", '+', 42424242);
- testClient.Transaction("22813371488", '-', 42);
- testClient.Transaction("00000000000", '+', 2281488);
- testClient.Transaction("12345678910", '+', 228);
- testClient.ShowAllAccounts();
- Console.WriteLine($"\nChecking history of an account 22813371488...");
- testClient.ShowAccountHistory("22813371488");
- Console.WriteLine("\nClosing an account 22813371488...\n");
- testClient.CloseAccount("22813371488");
- testClient.ShowAllAccounts();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement