Skip to content

Instantly share code, notes, and snippets.

@mattiasnordqvist
Last active February 4, 2020 10:46
Show Gist options
  • Save mattiasnordqvist/07f746fcc26a91ed2d815b3d85717ccf to your computer and use it in GitHub Desktop.
Save mattiasnordqvist/07f746fcc26a91ed2d815b3d85717ccf to your computer and use it in GitHub Desktop.
bankapp
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){}
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