Last active
February 4, 2020 10:46
-
-
Save mattiasnordqvist/07f746fcc26a91ed2d815b3d85717ccf to your computer and use it in GitHub Desktop.
bankapp
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
static void Main(string[] args) | |
{ | |
Console.WriteLine($"Enter 'accounts' to see a list of all current balances\nEnter 'log' to see the transaction log\nEnter a transfer command on format 'from -> to: amount' to make a transaction:"); | |
Console.WriteLine(); | |
while (true) | |
{ | |
Console.Write("> "); | |
var command = Console.ReadLine(); | |
if(command == "accounts") | |
{ | |
PrintAccounts(); | |
} | |
else if (command == "log") | |
{ | |
PrintTransactionLog(); | |
} | |
else | |
{ | |
var match = Regex.Match(command, @"(\w{1,}) *-> *(\w{1,}): *(\d{1,})"); | |
if (match.Success) | |
{ | |
Transfer(match.Groups[1].Value, match.Groups[2].Value, int.Parse(match.Groups[3].Value)); | |
} | |
else | |
{ | |
Console.WriteLine("Invalid command"); | |
} | |
} | |
Console.WriteLine(); | |
} | |
} | |
private static void PrintAccounts() {} | |
/// <summary> | |
/// Prints the latest 10 entries of the transaction log | |
/// </summary> | |
private static void PrintTransactionLog() {} | |
private static void Transfer(string fromCustomer, string toCustomer, int amount){} |
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
CREATE TABLE [dbo].[Account]( | |
[Balance] [int] NOT NULL CHECK(Balance >= 0), | |
[AccountNo] [int] NOT NULL PRIMARY KEY CHECK ((len([AccountNo])=(3) AND CONVERT([int],[AccountNo])>=(100))), | |
[Customer] [nvarchar](10) NOT NULL UNIQUE | |
) | |
CREATE TABLE TransactionLog | |
( | |
Id INT IDENTITY(1,1) PRIMARY KEY, | |
Moment DateTime NOT NULL, | |
[From] INT NOT NULL REFERENCES Account (AccountNo), | |
[To] INT NOT NULL REFERENCES Account (AccountNo), | |
Amount INT NOT NULL CHECK(Amount>0) | |
) | |
INSERT INTO Account (AccountNo, Customer, Balance) VALUES (555, 'Andersson', 1000) | |
INSERT INTO Account (AccountNo, Customer, Balance) VALUES (123, 'Petterson', 5000); | |
INSERT INTO Account (AccountNo, Customer, Balance) VALUES (333, 'Lundström', 2000); | |
INSERT INTO Account (AccountNo, Customer, Balance) VALUES (999, 'Jag', 10000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment