Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using Newtonsoft.Json;
- namespace ispit
- {
- class Program
- {
- static List<Customers> AllCustomers = new List<Customers>();
- static void Main(string[] args)
- {
- // data receiver
- if (System.IO.File.ReadAllText("./user.json").Length != 0)
- {
- var i = System.IO.File.ReadAllText("./user.json");
- AllCustomers = JsonConvert.DeserializeObject<List<Customers>>(i);
- foreach (var customer in AllCustomers)
- {
- var k = System.IO.File.ReadAllText("./user.json");
- AllCustomers = JsonConvert.DeserializeObject<List<Customers>>(k);
- }
- }
- // program
- while (true)
- {
- Console.WriteLine("Welcome to our bank \n 1. New Account \n 2. Operations \n 3. Exit \n*");
- int selection = Convert.ToInt32(Console.ReadLine());
- switch (selection)
- {
- case 1:
- NewAccount();
- break;
- case 2:
- SelectOperation2(SelectOperation1());
- break;
- case 3:
- Console.WriteLine("Operations done, goodbye!");
- break;
- default:
- Console.WriteLine("Invalid input!");
- break;
- }
- if(selection==3)
- {
- break;
- }
- Console.WriteLine("*");
- }
- // data saver
- foreach (var customer in AllCustomers)
- {
- var j = JsonConvert.SerializeObject(AllCustomers);
- System.IO.File.WriteAllText("./user.json", j);
- }
- }
- public static Customers NewAccount()
- {
- Customers ACustomer = new Customers();
- Console.WriteLine("Enter your name: ");
- ACustomer.Name = Console.ReadLine();
- Console.WriteLine("Enter your address: ");
- ACustomer.Address = Console.ReadLine();
- Console.WriteLine("Enter your phone number: ");
- ACustomer.Phone = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("The initial ammount: ");
- ACustomer.InitialAmmount = Convert.ToDouble(Console.ReadLine());
- Console.WriteLine("Enter your password: ");
- ACustomer.Password = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Re-enter your password: ");
- while (true)
- {
- int PwCheck = Convert.ToInt32(Console.ReadLine());
- if (PwCheck == ACustomer.Password)
- {
- Console.WriteLine("Password saved!");
- break;
- }
- else
- {
- Console.WriteLine("Passwords do not match, retype your password");
- }
- }
- ACustomer.AccountNumber = AllCustomers.Count;
- AllCustomers.Add(ACustomer);
- Console.WriteLine("Your account has successfully been created as: ");
- Console.WriteLine("Name: {0}\n Adress: {1}\n Phone number: {2}\n Initial ammount: {3}\n Account number: {4}\n Do not forget your account number and password",
- AllCustomers[ACustomer.AccountNumber].Name,
- AllCustomers[ACustomer.AccountNumber].Address,
- AllCustomers[ACustomer.AccountNumber].Phone,
- AllCustomers[ACustomer.AccountNumber].InitialAmmount,
- AllCustomers[ACustomer.AccountNumber].AccountNumber);
- return ACustomer;
- }
- public static int SelectOperation1()
- {
- Console.WriteLine("Enter your account number: ");
- int AccNmbr = Convert.ToInt32(Console.ReadLine());
- if (AccNmbr == AllCustomers[AccNmbr].AccountNumber)
- {
- Console.WriteLine("Enter your password: ");
- for (int i = 0; i < 3; i++)
- {
- if (i == 3)
- {
- Console.WriteLine("Your account has been blocked since your password is wrong. Call your bank! ");
- break;
- }
- int AccPw = Convert.ToInt32(Console.ReadLine());
- if (AccPw == AllCustomers[AccNmbr].Password)
- {
- Console.WriteLine("Entering: ");
- break;
- }
- Console.WriteLine("Re-enter your password: ");
- }
- }
- return AllCustomers[AccNmbr].AccountNumber;
- }
- public static int SelectOperation2 (int AccNmbr)
- {
- while(true)
- {
- Console.WriteLine("Choose an operation from the menu \n 1. Change Password \n 2. Deposite \n 3. Withdraw \n 4. Print \n 5. Exit");
- int input = Convert.ToInt32(Console.ReadLine());
- switch (input)
- {
- case 1:
- Operations.ChangePassword();
- break;
- case 2:
- double addition = Operations.Deposite(AllCustomers[AccNmbr].InitialAmmount);
- AllCustomers[AccNmbr].InitialAmmount = AllCustomers[AccNmbr].InitialAmmount + addition;
- break;
- case 3:
- double substract = Operations.Withdraw(AllCustomers[AccNmbr].InitialAmmount);
- AllCustomers[AccNmbr].InitialAmmount = AllCustomers[AccNmbr].InitialAmmount - substract;
- break;
- case 4:
- Operations.Print(AllCustomers[AccNmbr]);
- break;
- case 5:
- Console.WriteLine("Good Bye!");
- return 0;
- default:
- Console.WriteLine("Invalid input!");
- break;
- }
- Console.WriteLine("*");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement