YavorGrancharov

Optimized_Banking_System(class)

Jul 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Optimized_Banking_System
  6. {
  7.     class BankAccount
  8.     {
  9.         public string Name { get; set; }
  10.  
  11.         public string Bank { get; set; }
  12.  
  13.         public decimal Balance { get;  set; }
  14.     }
  15.  
  16.     class Program
  17.     {
  18.         static void Main(string[] args)
  19.         {
  20.             List<BankAccount> accounts = new List<BankAccount>();
  21.  
  22.             string input = Console.ReadLine();
  23.  
  24.             while (input != "end")
  25.             {
  26.                 string[] tokens = input.Split(new string[] { " | " },
  27.                     StringSplitOptions.RemoveEmptyEntries);
  28.  
  29.                 string bank = tokens[0];
  30.                 string name = tokens[1];
  31.                 decimal balance = decimal.Parse(tokens[2]);
  32.  
  33.                 BankAccount newBankAccount = new BankAccount
  34.                 {
  35.                     Bank = bank,
  36.                     Name = name,                    
  37.                     Balance = balance
  38.                 };
  39.  
  40.                 accounts.Add(newBankAccount);
  41.  
  42.                 input = Console.ReadLine();
  43.             }
  44.  
  45.             foreach (var account in accounts
  46.                 .OrderByDescending(accountBalance => accountBalance.Balance)
  47.                 .ThenBy(bankName => bankName.Bank.Length))
  48.             {
  49.                 Console.WriteLine("{0} -> {1} ({2})", account.Name, account.Balance, account.Bank);
  50.             }
  51.         }
  52.     }
  53. }
Add Comment
Please, Sign In to add comment