SHOW:
|
|
- or go back to the newest paste.
| 1 | using System; | |
| 2 | using System.Collections.Generic; | |
| 3 | using System.Linq; | |
| 4 | using System.Text; | |
| 5 | ||
| 6 | namespace ATM_Machine | |
| 7 | {
| |
| 8 | public class InputUtilities | |
| 9 | {
| |
| 10 | public static string GetInput(string inputType) | |
| 11 | {
| |
| 12 | string strInput = String.Empty; | |
| 13 | Console.Write("Enter your " + inputType + ": ");
| |
| 14 | strInput = Console.ReadLine(); | |
| 15 | ||
| 16 | return strInput; | |
| 17 | } | |
| 18 | public static string getStringInputValue(string inputType) | |
| 19 | {
| |
| 20 | string value = String.Empty; | |
| 21 | bool valid = false; | |
| 22 | string inputString = String.Empty; | |
| 23 | do | |
| 24 | {
| |
| 25 | inputString = GetInput(inputType); | |
| 26 | if (!String.IsNullOrEmpty(inputString)) | |
| 27 | {
| |
| 28 | value = inputString; | |
| 29 | valid = true; | |
| 30 | } | |
| 31 | else | |
| 32 | {
| |
| 33 | value = "Invalid input"; | |
| 34 | valid = false; | |
| 35 | } | |
| 36 | if (!valid) | |
| 37 | Console.WriteLine("Invalid " + inputType + " try again!");
| |
| 38 | } while (!valid); | |
| 39 | ||
| 40 | return value; | |
| 41 | } | |
| 42 | public static int getIntegerInputValue(string inputType) | |
| 43 | {
| |
| 44 | bool valid = false; | |
| 45 | int value = 0; | |
| 46 | string inputString = String.Empty; | |
| 47 | do | |
| 48 | {
| |
| 49 | inputString = GetInput(inputType); | |
| 50 | if (!(String.IsNullOrEmpty(inputString))) | |
| 51 | {
| |
| 52 | valid = Int32.TryParse(inputString, out value); | |
| 53 | } | |
| 54 | if (!valid) | |
| 55 | Console.WriteLine("Invalid " + inputType + " try again!");
| |
| 56 | } while (!valid); | |
| 57 | ||
| 58 | return value; | |
| 59 | } | |
| 60 | public static double getDoubleInputValue(string inputType) | |
| 61 | {
| |
| 62 | bool valid = false; | |
| 63 | double value = 0; | |
| 64 | string inputString = String.Empty; | |
| 65 | do | |
| 66 | {
| |
| 67 | inputString = GetInput(inputType); | |
| 68 | if (!(String.IsNullOrEmpty(inputString))) | |
| 69 | {
| |
| 70 | valid = Double.TryParse(inputString, out value); | |
| 71 | } | |
| 72 | if (!valid) | |
| 73 | Console.WriteLine("Invalid " + inputType + " try again!");
| |
| 74 | } while (!valid); | |
| 75 | ||
| 76 | return value; | |
| 77 | } | |
| 78 | public static char getCharInputValue(string inputType) | |
| 79 | {
| |
| 80 | bool valid = false; | |
| 81 | char value = 'u'; | |
| 82 | string inputString = String.Empty; | |
| 83 | do | |
| 84 | {
| |
| 85 | inputString = GetInput(inputType); | |
| 86 | if (!(String.IsNullOrEmpty(inputString))) | |
| 87 | {
| |
| 88 | valid = Char.TryParse(inputString, out value); | |
| 89 | } | |
| 90 | if (!valid) | |
| 91 | Console.WriteLine("Invalid " + inputType + " try again!");
| |
| 92 | } while (!valid); | |
| 93 | ||
| 94 | return value; | |
| 95 | } | |
| 96 | ||
| 97 | } | |
| 98 | } | |
| 99 | ||
| 100 | ||
| 101 | ||
| 102 | ||
| 103 | using System; | |
| 104 | using System.Collections.Generic; | |
| 105 | using System.Linq; | |
| 106 | using System.Text; | |
| 107 | using System.Threading.Tasks; | |
| 108 | ||
| 109 | namespace ATM_Machine | |
| 110 | {
| |
| 111 | class Program | |
| 112 | {
| |
| 113 | public static double balance = 0; | |
| 114 | public static void Main(string[] args) | |
| 115 | {
| |
| 116 | Console.WriteLine("*****Welcome to Junkie's ATM Machine*****");
| |
| 117 | Console.WriteLine("*****Press any key to get started*****");
| |
| 118 | Console.ReadLine(); | |
| 119 | makeSelection(); | |
| 120 | getPin(); | |
| 121 | userSelection(); | |
| 122 | } | |
| 123 | ||
| 124 | public static void makeSelection() | |
| 125 | {
| |
| 126 | Console.WriteLine("Press 1 to login. Press 2 to create new account");
| |
| 127 | int choice = InputUtilities.getIntegerInputValue("choice");
| |
| 128 | if (choice == 1) | |
| 129 | getUserName(); | |
| 130 | if (choice == 2) | |
| 131 | createAccount(); | |
| 132 | ||
| 133 | } | |
| 134 | ||
| 135 | public static void createAccount() | |
| 136 | {
| |
| 137 | ||
| 138 | Console.WriteLine("What is your desired username");
| |
| 139 | string selectedUserName = InputUtilities.getStringInputValue("desired username");
| |
| 140 | Console.WriteLine("Username set. Press any key to continue");
| |
| 141 | Console.ReadLine(); | |
| 142 | Console.WriteLine("What is your desired pin number");
| |
| 143 | int selectedPin = InputUtilities.getIntegerInputValue("desired pin");
| |
| 144 | Console.WriteLine("Pin set. Press any key to login");
| |
| 145 | Console.ReadLine(); | |
| 146 | string username; | |
| 147 | Console.WriteLine("*****IDENITIFY YOURSELF*****");
| |
| 148 | Console.WriteLine("What is your username?");
| |
| 149 | username = InputUtilities.getStringInputValue("username");
| |
| 150 | if (username != selectedUserName) | |
| 151 | do | |
| 152 | {
| |
| 153 | Console.WriteLine("Invalid Username");
| |
| 154 | username = InputUtilities.getStringInputValue("username");
| |
| 155 | } while (username != selectedUserName); | |
| 156 | else | |
| 157 | {
| |
| 158 | Console.WriteLine("What is your pin?");
| |
| 159 | } | |
| 160 | int pin = InputUtilities.getIntegerInputValue("pin");
| |
| 161 | if (pin != selectedPin) | |
| 162 | do | |
| 163 | {
| |
| 164 | Console.WriteLine("Invalid Pin");
| |
| 165 | pin = InputUtilities.getIntegerInputValue("username");
| |
| 166 | } while (pin != selectedPin); | |
| 167 | else | |
| 168 | {
| |
| 169 | Console.WriteLine("Welcome " + username);
| |
| 170 | userSelection(); | |
| 171 | } | |
| 172 | } | |
| 173 | ||
| 174 | ||
| 175 | ||
| 176 | public static void getUserName() | |
| 177 | {
| |
| 178 | string username; | |
| 179 | Console.WriteLine("*****IDENITIFY YOURSELF*****");
| |
| 180 | Console.WriteLine("What is your username?");
| |
| 181 | username = InputUtilities.getStringInputValue("username");
| |
| 182 | if (username != "junkie") | |
| 183 | invalidUsername(); | |
| 184 | } | |
| 185 | ||
| 186 | public static void invalidUsername() | |
| 187 | {
| |
| 188 | string username; | |
| 189 | do | |
| 190 | {
| |
| 191 | Console.WriteLine("Invalid Username");
| |
| 192 | username = InputUtilities.getStringInputValue("username");
| |
| 193 | } while (username != "junkie"); | |
| 194 | } | |
| 195 | ||
| 196 | public static void getPin() | |
| 197 | {
| |
| 198 | int pin; | |
| 199 | Console.WriteLine("*****ENTER YOUR PIN*****");
| |
| 200 | Console.WriteLine("What is your pin number?");
| |
| 201 | pin = InputUtilities.getIntegerInputValue("pin");
| |
| 202 | if (pin != 5432) | |
| 203 | invalidPin(); | |
| 204 | } | |
| 205 | ||
| 206 | public static void invalidPin() | |
| 207 | {
| |
| 208 | int pin; | |
| 209 | do | |
| 210 | {
| |
| 211 | Console.WriteLine("Invalid Pin Number");
| |
| 212 | pin = InputUtilities.getIntegerInputValue("pin");
| |
| 213 | } while (pin != 5432); | |
| 214 | } | |
| 215 | ||
| 216 | public static void userSelection() | |
| 217 | {
| |
| 218 | Console.WriteLine("*****Welcome to the ATM Machine Menu*****");
| |
| 219 | Console.WriteLine("What would you like to do?");
| |
| 220 | Console.WriteLine("To Check Balance Press [1]. To input money Press [2]. To withdraw Press [3]. To exit Press [4]. ");
| |
| 221 | int selection = InputUtilities.getIntegerInputValue("selection");
| |
| 222 | if (selection == 1) | |
| 223 | checkBalance(); | |
| 224 | if (selection == 2) | |
| 225 | inputMoney(); | |
| 226 | if (selection == 3) | |
| 227 | withdraw(); | |
| 228 | if (selection == 4) | |
| 229 | terminate(); | |
| 230 | } | |
| 231 | ||
| 232 | public static void checkBalance() | |
| 233 | {
| |
| 234 | Console.WriteLine("*****YOUR BALANCE*****");
| |
| 235 | Console.WriteLine("Your balance is " + balance);
| |
| 236 | Console.ReadLine(); | |
| 237 | userSelection(); | |
| 238 | } | |
| 239 | ||
| 240 | public static void inputMoney() | |
| 241 | {
| |
| 242 | Console.WriteLine("*****Input Money*****");
| |
| 243 | Console.WriteLine("How much would you like to input?");
| |
| 244 | double inputAmount = InputUtilities.getIntegerInputValue("amount");
| |
| 245 | balance = balance + inputAmount; | |
| 246 | Console.WriteLine("Your new balance is " + balance + " ***Press ENTER to return to the menu***");
| |
| 247 | Console.ReadLine(); | |
| 248 | userSelection(); | |
| 249 | } | |
| 250 | public static void withdraw() | |
| 251 | {
| |
| 252 | Console.WriteLine("*****Withdraw From Your Account*****");
| |
| 253 | Console.WriteLine("How much would you like to withdraw?");
| |
| 254 | double withdrawAmount = InputUtilities.getDoubleInputValue("amount to take");
| |
| 255 | if (withdrawAmount > balance) | |
| 256 | Console.WriteLine("You don't have enough for that");
| |
| 257 | else if (withdrawAmount <= balance) | |
| 258 | balance = balance - withdrawAmount; | |
| 259 | Console.WriteLine("Your new balance is " + balance + " ***Press ENTER to return to the menu***");
| |
| 260 | Console.ReadLine(); | |
| 261 | userSelection(); | |
| 262 | } | |
| 263 | ||
| 264 | public static void terminate() | |
| 265 | {
| |
| 266 | Console.WriteLine("Thank you. Press any key to terminate the program...");
| |
| 267 | Console.ReadLine(); | |
| 268 | ||
| 269 | } | |
| 270 | } | |
| 271 | } |