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;
- /* REMEMBER FORMATTING CHECK*/
- /* REMEMBER FORMATTING CHECK*/
- /* REMEMBER FORMATTING CHECK*/
- /* REMEMBER FORMATTING CHECK*/
- /* REMEMBER FORMATTING CHECK*/
- /* REMEMBER FORMATTING CHECK*/
- /* REMEMBER FORMATTING CHECK*/
- /* REMEMBER FORMATTING CHECK*/
- namespace Assessment_1__ATM
- {
- class ATM
- {
- const int CHECK_BALANCE = 1;
- const int WITHDRAWAL = 2;
- const int TRANSFER = 3;
- const int SAVINGS_ACCOUNT = 1;
- const int DEBIT_CARD = 2;
- const int CREDIT_CARD = 3;
- const int LINE_OF_CREDIT = 4;
- const int EXIT = 0;
- const int HIGHEST_INCREMENT = 50;
- const int LOWEST_INCREMENT = 20;
- const double FEE = 0.1;
- static double savingsBalance = 901.45;
- static double debitCardBalance = 450;
- static double creditCardBalance = 1500;
- static double lineOfCreditBalance = 2000;
- static void DisplayMainMenu()
- {
- {
- string menu = "\nWelcome to EziTeller ATM Machine"
- + "\n\n\tTransaction Menu"
- + "\n\t================"
- + "\n\t1. Check Balance"
- + "\n\n\t2. Withdrawal"
- + "\n\n\t3. Transfer"
- + "\n\n\n\n\nPlease enter your choice 1 ... 3 or 0 to Exit:";
- Console.Write(menu);
- }
- }
- static void DisplaySubMenu()
- {
- {
- string menu = "\n\n\t1. Savings Account"
- + "\n\n\t2. Debit Card"
- + "\n\n\t3. Credit Card"
- + "\n\n\t4. Line of Credit"
- + "\n\n\n\nPlease enter your choice 1 ... 4 or 0 to Exit:";
- Console.Write(menu);
- }
- }
- static int ReadOption(Boolean mainmenu)
- {
- int lowestValue = 0;
- int highestValue = 0;
- int option = 0;
- bool validMenuOption = false;
- if (mainmenu == true)
- {
- lowestValue = CHECK_BALANCE;
- highestValue = TRANSFER;
- }
- else
- {
- lowestValue = SAVINGS_ACCOUNT;
- highestValue = LINE_OF_CREDIT;
- }
- do
- {
- option = int.Parse(Console.ReadLine());
- if ((EXIT <= option) && (option <= highestValue))
- {
- validMenuOption = true;
- }
- else {
- Console.WriteLine("\n\tOption must be {0} ... {1} or {2} to Exit.",
- lowestValue, highestValue, EXIT);
- DisplayMainMenu();
- }
- }
- while (!validMenuOption);
- return option;
- }
- static string SetAccountName(int whichAccount)
- {
- if (whichAccount == SAVINGS_ACCOUNT) {
- return "Savings Account";
- }
- if (whichAccount == DEBIT_CARD) {
- return "Debit Card";
- }
- if (whichAccount == CREDIT_CARD) {
- return "Credit Card";
- }
- else {
- return "Line of Credit";
- }
- }
- static double SetBalance(int whichAccount)
- {
- if (whichAccount == SAVINGS_ACCOUNT) {
- return savingsBalance;
- }
- if (whichAccount == DEBIT_CARD) {
- return debitCardBalance;
- }
- if (whichAccount == CREDIT_CARD) {
- return creditCardBalance;
- }
- else {
- return lineOfCreditBalance;
- }
- }
- static bool SetFee(int whichAccount)
- {
- if (whichAccount == CREDIT_CARD || whichAccount == DEBIT_CARD) {
- return true;
- }
- else
- {
- return false;
- }
- }
- static void DisplayBalance(int whichAccount)
- {
- string accountName = "";
- double balance = 0;
- DateTime date = DateTime.Now;
- Console.WriteLine("\nCurrent Date: {0} ", date);
- accountName = SetAccountName(whichAccount);
- balance = SetBalance(whichAccount);
- Console.WriteLine("\nBalance of {0} is ${1}.", accountName, balance);
- }
- static int IncrementalCheck() {
- int amount = 0;
- while (true) {
- Console.WriteLine("Please enter amount:");
- amount = int.Parse(Console.ReadLine());
- if (amount % HIGHEST_INCREMENT != 0 && amount % 20 != 0) {
- Console.WriteLine("Sorry, we cannot dispense {0}.", amount);
- }
- else {
- return amount;
- }
- }
- }
- static void DispenseCash(int amount) {
- int withdrawalAmount = amount;
- int highestIncrementNotes = 0;
- int lowestIncrementNotes = 0;
- if ((amount % LOWEST_INCREMENT == 0) && amount % LOWEST_INCREMENT != 0) {
- while (amount >= LOWEST_INCREMENT) {
- lowestIncrementNotes += 1;
- amount = amount - LOWEST_INCREMENT;
- }
- }
- if (amount % HIGHEST_INCREMENT == 0) {
- while (amount >= HIGHEST_INCREMENT) {
- highestIncrementNotes += 1;
- amount = amount - HIGHEST_INCREMENT;
- }
- }
- else {
- while ((amount >= HIGHEST_INCREMENT) && (amount % HIGHEST_INCREMENT != 0)) {
- amount = amount - HIGHEST_INCREMENT;
- highestIncrementNotes += 1;
- }
- if (amount % LOWEST_INCREMENT == 0) {
- while (amount >= LOWEST_INCREMENT) {
- amount = amount - LOWEST_INCREMENT;
- lowestIncrementNotes += 1;
- }
- }
- }
- Console.WriteLine("\nPlease collect ${0} consisting of:", withdrawalAmount);
- Console.WriteLine("\n\n\t{0} x ${1} notes", highestIncrementNotes, HIGHEST_INCREMENT);
- Console.WriteLine("\t\tand");
- Console.WriteLine("\n\n\t{0} x ${1} notes", lowestIncrementNotes, LOWEST_INCREMENT);
- }
- static void TransferAmount(int fromAccount, int toAccount) {
- }
- static void WithrawAmount(int whichAccount)
- {
- int withdrawalAmount = IncrementalCheck();
- double balance = SetBalance(whichAccount);
- if (SetFee(whichAccount) == false) {
- if (balance < withdrawalAmount) {
- Console.WriteLine("\nYou have insufficient funds.");
- }
- else {
- if (whichAccount == SAVINGS_ACCOUNT) {
- savingsBalance = savingsBalance - withdrawalAmount;
- }
- if (whichAccount == LINE_OF_CREDIT) {
- lineOfCreditBalance = lineOfCreditBalance - withdrawalAmount;
- }
- DispenseCash(withdrawalAmount);
- DisplayBalance(whichAccount);
- }
- }
- else {
- if (balance < (withdrawalAmount + FEE)) {
- Console.WriteLine("\nYou have insufficient funds.");
- }
- else {
- if (whichAccount == CREDIT_CARD) {
- creditCardBalance = creditCardBalance - withdrawalAmount;
- }
- if (whichAccount == DEBIT_CARD) {
- debitCardBalance = debitCardBalance - withdrawalAmount;
- }
- DispenseCash(withdrawalAmount);
- DisplayBalance(whichAccount);
- }
- }
- }
- static void Main()
- {
- int transactionOption;
- int accountOption;
- while (true)
- {
- DisplayMainMenu();
- transactionOption = ReadOption(true);
- DisplaySubMenu();
- accountOption = ReadOption(false);
- if (transactionOption == CHECK_BALANCE)
- {
- DisplayBalance(accountOption);
- }
- if (transactionOption == WITHDRAWAL)
- {
- WithrawAmount(accountOption);
- }
- if (transactionOption == TRANSFER) {
- ReadOption(false);
- Console.WriteLine("Transfer from which account?");
- TransferAmount();
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment