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;
- namespace atm {
- class ATM {
- const int SAVING_ACCOUNT = 1;
- const int DEBIT_CARD = 2;
- const int CREDIT_CARD = 3;
- const int LINE_OF_CREDIT = 4;
- static double[] accountBalances = { 0.0, 901.45, 450.0, 1500.0, 2000.0 };
- static string[] accountTypes = { "", "Savings Account", "Debit Card", "Credit Card",
- "Line of Credit Account" };
- static void Main(string[] args) {
- while (true) {
- Console.WriteLine("Welcome to Sam's ATM Simulator \n Transaction Menu");
- Console.WriteLine(" ================\n 1. Check Balance\n 2. Withdrawal");
- Console.Write(" 3. Transfer\n\n\nPlease Enter your choice 1 ... 3 or 0 to exit: ");
- string input = Console.ReadLine();
- if (input == "1") CheckBalanceMain();
- else if (input == "2") WithdrawalMain();
- else if (input == "3") TransferMain();
- else if (input == "0") Environment.Exit(0);
- else Console.WriteLine("You pressed an invalid character! Try again.\n\n");
- }
- }
- static void CheckBalanceMain() {
- Console.WriteLine("\n\n 1. Savings Account\n 2. Debit Card\n 3. Credit Card");
- Console.Write(" 4. Line of Credit\n \nPlease Enter your choice 1 ... 4 or 0 to return: ");
- string input = Console.ReadLine();
- int whichAccount = Convert.ToInt32(input);
- if (whichAccount > 0) DisplayBalance(whichAccount);
- else Main(new String[0]);
- }
- static void DisplayBalance(int whichAccount) {
- Date();
- Console.WriteLine("\n\nBalance of {0} is {1}\n",
- accountTypes[whichAccount], accountBalances[whichAccount]);
- Main(new String[0]);
- }
- static void Date() {
- DateTime date = DateTime.Now;
- Console.WriteLine("Current Date: {0} ", date);
- }
- static void WithdrawalMain() {
- Console.WriteLine("\n\n 1. Savings Account\n 2. Debit Card\n 3. Credit Card");
- Console.Write(" 4. Line of Credit\n \nPlease Enter your choice 1 ... 4 or 0 to return: ");
- string input = Console.ReadLine();
- int whichAccount = Convert.ToInt32(input);
- if (whichAccount > 0) WithdrawAmount(whichAccount);
- }
- static void WithdrawAmount(int whichAccount) {
- Console.WriteLine("Please enter amount to withdraw: "); double amount = Convert.ToDouble(Console.ReadLine());
- // Checks if amount is a a multiple of 10, and is not 10 or 30 (because you can have any odd multiple of 10, but ONLY if it above 30
- if (amount % 10 == 0 & amount != 10 & amount != 30)
- {
- if ((accountBalances[whichAccount]) - amount < 10) {
- Console.WriteLine("There are insufficient funds in {0}", accountTypes[whichAccount]); WithdrawAmount(whichAccount);
- } else {
- if (accountTypes[whichAccount] == "Debit Card" || accountTypes[whichAccount] == "Credit Card") accountBalances[whichAccount] -= 0.10;
- accountBalances[whichAccount] -= amount; DispenseCash(amount, whichAccount);
- }
- } else {
- //since we're calling this again we dont want the arithmatic to be calculated twice
- Console.WriteLine(" {0} cannot be dispensed.", amount); WithdrawAmount(whichAccount);
- }
- }
- static void DispenseCash(double amount, int whichAccount) {
- int numlargenotes = (int)amount / 50;
- int numsmallnotes = 0;
- //a temporary variable, as we can't declare it in an if statement
- if (amount % 50 == 10 || amount % 50 == 30) {
- numlargenotes = numlargenotes - 1;
- numsmallnotes = (int)(amount - (50 * numlargenotes)) / 20;
- } else
- numsmallnotes = (int)amount % 50 / 20;
- Console.WriteLine("\nPlease collect ${0} consisting of:\n{1} $50.00 notes and {2} $20.00 notes.\n",
- amount, numlargenotes, numsmallnotes);
- Date();
- Console.WriteLine("Balance of {0} is {1}.\n", accountTypes[whichAccount], accountBalances[whichAccount]);
- }
- static void TransferMain() {
- Console.WriteLine("\n 1. Savings Account\n 2. Debit Card\n 2. Debit Card");
- Console.WriteLine(" 3. Credit Card\n 4. Line of Credit\n");
- Console.WriteLine("Transfer from which account? ");
- Console.Write("Please Enter your choice 1 ... 4 or 0 to return: ");
- int fromAccount = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("\nTransfer to which account?");
- Console.Write("Please Enter your choice 1 ... 4 or 0 to return: ");
- int toAccount = Convert.ToInt32(Console.ReadLine());
- if (fromAccount > 0 & toAccount > 0)
- if (fromAccount == toAccount) Console.WriteLine("Must select two different accounts");
- else TransferAmount(fromAccount, toAccount);
- }
- static void TransferAmount(int fromAccount, int toAccount) {
- Console.Write("Please enter amount to Transfer: ");
- string input = Console.ReadLine();
- double amount = Convert.ToDouble(input);
- if (accountBalances[fromAccount] - accountBalances[toAccount] < 10)
- Console.WriteLine("Insufficient Funds to complete transaction");
- else {
- accountBalances[fromAccount] = accountBalances[fromAccount] - amount - 0.5;
- accountBalances[toAccount] = accountBalances[toAccount] + amount;
- Console.WriteLine("Transaction was successful.\n");
- Date();
- Console.WriteLine("Balance of {0} is {1}", accountTypes[fromAccount], accountBalances[fromAccount]);
- Console.WriteLine("Balance of {0} is {1}", accountTypes[toAccount], accountBalances[toAccount]);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment