using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ATM_Machine { public class InputUtilities { public static string GetInput(string inputType) { string strInput = String.Empty; Console.Write("Enter your " + inputType + ": "); strInput = Console.ReadLine(); return strInput; } public static string getStringInputValue(string inputType) { string value = String.Empty; bool valid = false; string inputString = String.Empty; do { inputString = GetInput(inputType); if (!String.IsNullOrEmpty(inputString)) { value = inputString; valid = true; } else { value = "Invalid input"; valid = false; } if (!valid) Console.WriteLine("Invalid " + inputType + " try again!"); } while (!valid); return value; } public static int getIntegerInputValue(string inputType) { bool valid = false; int value = 0; string inputString = String.Empty; do { inputString = GetInput(inputType); if (!(String.IsNullOrEmpty(inputString))) { valid = Int32.TryParse(inputString, out value); } if (!valid) Console.WriteLine("Invalid " + inputType + " try again!"); } while (!valid); return value; } public static double getDoubleInputValue(string inputType) { bool valid = false; double value = 0; string inputString = String.Empty; do { inputString = GetInput(inputType); if (!(String.IsNullOrEmpty(inputString))) { valid = Double.TryParse(inputString, out value); } if (!valid) Console.WriteLine("Invalid " + inputType + " try again!"); } while (!valid); return value; } public static char getCharInputValue(string inputType) { bool valid = false; char value = 'u'; string inputString = String.Empty; do { inputString = GetInput(inputType); if (!(String.IsNullOrEmpty(inputString))) { valid = Char.TryParse(inputString, out value); } if (!valid) Console.WriteLine("Invalid " + inputType + " try again!"); } while (!valid); return value; } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ATM_Machine { class Program { public static double balance = 0; public static void Main(string[] args) { Console.WriteLine("*****Welcome to Junkie's ATM Machine*****"); Console.WriteLine("*****Press any key to get started*****"); Console.ReadLine(); makeSelection(); getPin(); userSelection(); } public static void makeSelection() { Console.WriteLine("Press 1 to login. Press 2 to create new account"); int choice = InputUtilities.getIntegerInputValue("choice"); if (choice == 1) getUserName(); if (choice == 2) createAccount(); } public static void createAccount() { Console.WriteLine("What is your desired username"); string selectedUserName = InputUtilities.getStringInputValue("desired username"); Console.WriteLine("Username set. Press any key to continue"); Console.ReadLine(); Console.WriteLine("What is your desired pin number"); int selectedPin = InputUtilities.getIntegerInputValue("desired pin"); Console.WriteLine("Pin set. Press any key to login"); Console.ReadLine(); string username; Console.WriteLine("*****IDENITIFY YOURSELF*****"); Console.WriteLine("What is your username?"); username = InputUtilities.getStringInputValue("username"); if (username != selectedUserName) do { Console.WriteLine("Invalid Username"); username = InputUtilities.getStringInputValue("username"); } while (username != selectedUserName); else { Console.WriteLine("What is your pin?"); } int pin = InputUtilities.getIntegerInputValue("pin"); if (pin != selectedPin) do { Console.WriteLine("Invalid Pin"); pin = InputUtilities.getIntegerInputValue("username"); } while (pin != selectedPin); else { Console.WriteLine("Welcome " + username); userSelection(); } } public static void getUserName() { string username; Console.WriteLine("*****IDENITIFY YOURSELF*****"); Console.WriteLine("What is your username?"); username = InputUtilities.getStringInputValue("username"); if (username != "junkie") invalidUsername(); } public static void invalidUsername() { string username; do { Console.WriteLine("Invalid Username"); username = InputUtilities.getStringInputValue("username"); } while (username != "junkie"); } public static void getPin() { int pin; Console.WriteLine("*****ENTER YOUR PIN*****"); Console.WriteLine("What is your pin number?"); pin = InputUtilities.getIntegerInputValue("pin"); if (pin != 5432) invalidPin(); } public static void invalidPin() { int pin; do { Console.WriteLine("Invalid Pin Number"); pin = InputUtilities.getIntegerInputValue("pin"); } while (pin != 5432); } public static void userSelection() { Console.WriteLine("*****Welcome to the ATM Machine Menu*****"); Console.WriteLine("What would you like to do?"); Console.WriteLine("To Check Balance Press [1]. To input money Press [2]. To withdraw Press [3]. To exit Press [4]. "); int selection = InputUtilities.getIntegerInputValue("selection"); if (selection == 1) checkBalance(); if (selection == 2) inputMoney(); if (selection == 3) withdraw(); if (selection == 4) terminate(); } public static void checkBalance() { Console.WriteLine("*****YOUR BALANCE*****"); Console.WriteLine("Your balance is " + balance); Console.ReadLine(); userSelection(); } public static void inputMoney() { Console.WriteLine("*****Input Money*****"); Console.WriteLine("How much would you like to input?"); double inputAmount = InputUtilities.getIntegerInputValue("amount"); balance = balance + inputAmount; Console.WriteLine("Your new balance is " + balance + " ***Press ENTER to return to the menu***"); Console.ReadLine(); userSelection(); } public static void withdraw() { Console.WriteLine("*****Withdraw From Your Account*****"); Console.WriteLine("How much would you like to withdraw?"); double withdrawAmount = InputUtilities.getDoubleInputValue("amount to take"); if (withdrawAmount > balance) Console.WriteLine("You don't have enough for that"); else if (withdrawAmount <= balance) balance = balance - withdrawAmount; Console.WriteLine("Your new balance is " + balance + " ***Press ENTER to return to the menu***"); Console.ReadLine(); userSelection(); } public static void terminate() { Console.WriteLine("Thank you. Press any key to terminate the program..."); Console.ReadLine(); } } }