Advertisement
Guest User

Untitled

a guest
Dec 4th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6.  
  7.  
  8. namespace Prog1_Methods_Ex1_Ludwig_Kennberg_Te16B
  9. {
  10.     class Program  
  11.     {
  12.  
  13.         static string username;
  14.         static string userpassword;
  15.         static string userfirstname;
  16.         static string userlastname;
  17.         static string adress;
  18.         static string usercardnumber;
  19.         static string userphonenumber;
  20.         static double balance = 0;
  21.         static void Main(string[] args)
  22.         {
  23.             LogInMenu(); //calls the login menu
  24.         }
  25.         static void LogInMenu()
  26.         {
  27.             Console.Clear();
  28.             Console.BackgroundColor = ConsoleColor.White;
  29.             Console.ForegroundColor = ConsoleColor.Black;
  30.             Console.WriteLine("Välkommen till Banken!");
  31.             Console.BackgroundColor = ConsoleColor.Black;
  32.             Console.ForegroundColor = ConsoleColor.Gray;
  33.             Console.WriteLine("[1] Logga in");
  34.             Console.WriteLine("[2] Skapa nytt konto");
  35.             Console.WriteLine("[3] Avsluta");
  36.            
  37.  
  38.             int option = (Console.ReadKey().GetHashCode());
  39.  
  40.             if (option == 49) //If the user selects 1, the user enters the user loginmenu
  41.             {
  42.                 userLogIn();
  43.             }
  44.             else if (option == 50) //If the user selects 1, the user enters the createaccountmeny
  45.             {
  46.                 UserCreateAccount();
  47.             }
  48.             else if (option == 51) //If the user selects 1, they will shut down the console
  49.             {
  50.                 Environment.Exit(0);
  51.             }
  52.             else
  53.             {
  54.                 Console.WriteLine("Ogiltigt kommando!");
  55.                 LogInMenu();
  56.             }
  57.            
  58.         }
  59.         static void userLogIn()
  60.         {
  61.             Console.Clear();
  62.             Console.Write("Användarnamn: ");
  63.             string USERNAME = Console.ReadLine();
  64.             Console.Write("Lösenord: ");
  65.             string PASSWORD = Console.ReadLine();
  66.            
  67.             if (USERNAME == username && PASSWORD == userpassword)  //if the username and password that the user entered when creating the account is the same as in the login, you will continue to the main menu.
  68.             {
  69.                 Console.Clear();
  70.                 Console.ForegroundColor = ConsoleColor.Green;
  71.                 Console.WriteLine("Inloggningen lyckades!, vänligen vänta medans vi loggar in dig!");
  72.                 Thread.Sleep(5000);
  73.  
  74.                 Console.ForegroundColor = ConsoleColor.Gray;
  75.             }
  76.             else if (USERNAME != username || PASSWORD != userpassword) //if the username and password that the user entered when creating the account is not the same as in the login, you will get asked to, log in again or go back to the loginmenu.
  77.             {
  78.                 Console.Clear();
  79.                 Console.ForegroundColor = ConsoleColor.Red;
  80.                 Console.WriteLine("Inloggningen misslyckades, Vänligen försök igen!");
  81.                 Console.ForegroundColor = ConsoleColor.Gray;
  82.                 Console.WriteLine("[1] Logga in igen!");
  83.                 Console.WriteLine("[2] Gå tillbaka till menyn!");
  84.                 int option = (Console.ReadKey().GetHashCode());
  85.  
  86.                 if (option == 49) //If the user selects 1, the user enters the log in menu again
  87.                 {
  88.                     userLogIn();
  89.                 }
  90.                 if (option == 50) //If the user selects 2, the user enters the first menu
  91.                 {
  92.                     LogInMenu();
  93.                 }
  94.  
  95.                 Console.ForegroundColor = ConsoleColor.Gray;
  96.                
  97.             }
  98.         }
  99.         static void UserCreateAccount()
  100.         {
  101.             Console.Clear();          
  102.             Console.BackgroundColor = ConsoleColor.White;
  103.             Console.ForegroundColor = ConsoleColor.Black;
  104.             Console.WriteLine("Vänligen skapa ditt konto");
  105.             Console.BackgroundColor = ConsoleColor.Black;
  106.             Console.ForegroundColor = ConsoleColor.Gray;
  107.             Console.Write("Förnamn: ");
  108.             string userfirstname = Console.ReadLine();
  109.             Console.Write("Efternamn: ");
  110.             string userlastname = Console.ReadLine();
  111.             Console.Write("Telefonnummer: ");
  112.             long userphonenumber;
  113.  
  114.             //makes an error if typing your phonenumber in chars
  115.             while (!long.TryParse(Console.ReadLine(), out userphonenumber))
  116.             {
  117.                 Console.ForegroundColor = ConsoleColor.Red;
  118.                 Console.WriteLine("");
  119.                 Console.Write("Vänligen skriv in ditt telefon nummer igen!");
  120.                 Console.Write("Telefon nummret får endast innehålla siffror!");
  121.                 Console.Write("");
  122.                 Console.ForegroundColor = ConsoleColor.Gray;
  123.                 Console.Write("Telefonnummer: ");
  124.  
  125.             }
  126.             Console.Write("Adress: ");
  127.             string adress = Console.ReadLine();
  128.             Console.Write("Kortnummer: ");
  129.             string usercardnumber = Console.ReadLine();
  130.             //makes an error if the amount of numbers in the cardnumber is shorter than 13 and longer than 19, then request the user to rewrite their cardnumber.
  131.             while (usercardnumber.Length >19 || usercardnumber.Length < 13)
  132.             {
  133.                     Console.ForegroundColor = ConsoleColor.Red;
  134.                     Console.WriteLine("");
  135.                     Console.WriteLine("Vänligen skriv in ditt kortnummer igen!");
  136.                     Console.WriteLine("Ditt kortnummer får endast vara mellan, 13 och 19 siffror långt!");
  137.                     Console.WriteLine("");
  138.                     Console.ForegroundColor = ConsoleColor.Gray;
  139.                     Console.Write("Kortnummer: ");
  140.                     usercardnumber = Console.ReadLine();
  141.             }
  142.             Console.Write("Användarnamn: ");
  143.             username = Console.ReadLine();
  144.             Console.Write("Lösenord: ");
  145.             userpassword = Console.ReadLine();
  146.  
  147.             LogInMenu();
  148.  
  149.             MainMenu(userfirstname, userlastname, userphonenumber, adress, usercardnumber);
  150.         }
  151.         static void MainMenu(string userfirstname, string userlastname, long userphonenumber, string adress, string usercardnumber)
  152.         {
  153.             Account bank = new Account();
  154.  
  155.             while (true) //why I just choosed to use me out of a while rate and not a for rate was because I knew that the user will repeat the menu several times, a while rate can be repeated unexpectedly with times while a for rate can not
  156.             {
  157.                
  158.                 Console.WriteLine("Ditt kontosaldo är: " + balance + ".00kr");
  159.                 Console.BackgroundColor = ConsoleColor.White;
  160.                 Console.ForegroundColor = ConsoleColor.Black;
  161.                 Console.WriteLine("\nVälkommen " + userfirstname + " " + userlastname + "!"); //Writing out "Welcome" + the first name and last name that the user entered when creating the account.
  162.                 Console.BackgroundColor = ConsoleColor.Black;
  163.                 Console.ForegroundColor = ConsoleColor.Gray;
  164.                 Console.WriteLine("[1]Insättning");
  165.                 Console.WriteLine("[2]Uttag");
  166.                 Console.WriteLine("[3]Konto detaljer");
  167.                 Console.WriteLine("[4]Logga ut");
  168.                 Console.WriteLine("[5]Avsluta");
  169.                
  170.                 int choice = (Console.ReadKey().GetHashCode());
  171.  
  172.                 if (choice == 49) //If the user selects 1, the user will get asked how much money he want to deposit
  173.                 {
  174.                     balance = bank.deposit();
  175.                 }
  176.                 if (choice == 50) //If the user selects 2, the user will get asked how much money he wants to withdraw
  177.                 {
  178.                     balance = bank.withdraw();
  179.                 }
  180.  
  181.                 if (choice == 51) //If the user selects 3, the user enters the accountdetail method which will show what information the user entered when creating the account
  182.                 {
  183.                     accountDetail(userfirstname, userlastname, userphonenumber, adress, usercardnumber);
  184.                 }
  185.                 if (choice == 52) //If the user selects 1, the user enters the frst menu
  186.                 {
  187.                     LogInMenu();
  188.                 }
  189.                 if (choice == 53) //If the user selects 1, they will shut down the program
  190.                 {
  191.                     Environment.Exit(0);
  192.                 }
  193.                 MainMenu(userfirstname, userlastname, userphonenumber, adress, usercardnumber);
  194.             }
  195.         }
  196.         public class Account
  197.         {
  198.             //asks the user to enter how much money the user wants to deposit, and then add the value of the balance
  199.             public double deposit() //why I use a static double is because I want to return a value, in this case, the deposit
  200.             {
  201.                 Console.Clear();
  202.                 double deposit;
  203.  
  204.                 Console.Write("Hur mycket pengar vill du sätta in: ");
  205.                 deposit = Double.Parse(Console.ReadLine());
  206.                 balance += deposit;
  207.                 return balance;
  208.             }
  209.             //asks the user to enter how much money the user wants to withdraw, and then removing the value from the balance
  210.             public double withdraw() //why I use a static double is because I want to return a value, in this case, the withdraw
  211.             {
  212.                 Console.Clear();
  213.                 double withdraw;
  214.                 Console.Write("Hur mycket pengar vill du ta ut: ");
  215.                 withdraw = Double.Parse(Console.ReadLine());
  216.                 //makes an error if the amount the user wants to withdraw is bigger than the balance
  217.                 if (withdraw > balance)
  218.                 {
  219.                     Console.ForegroundColor = ConsoleColor.Red;
  220.                     Console.WriteLine("Uttagning misslyckades!");
  221.                     Console.WriteLine("Ditt uttag överskrider ditt kontosaldo!");
  222.                     Console.ForegroundColor = ConsoleColor.Gray;
  223.                 }
  224.                 else { balance -= withdraw; }
  225.  
  226.                 return balance;
  227.             }
  228.         }
  229.         static void accountDetail(string userfirstname, string userlastname, long userphonenumber, string adress, string usercardnumber)
  230.         {
  231.             Console.Clear();
  232.             Console.BackgroundColor = ConsoleColor.White;
  233.             Console.ForegroundColor = ConsoleColor.Black;
  234.             Console.WriteLine("Konto detaljer!");
  235.             Console.BackgroundColor = ConsoleColor.Black;
  236.             Console.ForegroundColor = ConsoleColor.Green;
  237.             Console.WriteLine(" ");
  238.             Console.WriteLine("Förnamn:" + userfirstname);
  239.             Console.WriteLine("Efternamn:" + userlastname);
  240.             Console.WriteLine("Telefonnummer: " + userphonenumber);
  241.             Console.WriteLine("Adress:" + adress);
  242.             Console.WriteLine("Kortnummer:" + usercardnumber);
  243.             Console.WriteLine("Användarnamn:" + username);
  244.             Console.WriteLine("Lösenord:" + userpassword);
  245.             Console.WriteLine("");
  246.             Console.ForegroundColor = ConsoleColor.Gray;
  247.         }
  248.     }
  249. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement