Advertisement
Guest User

Untitled

a guest
Jan 21st, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace BankÖvning
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Account acc = new Account();
  14.             Bank bank = new Bank();
  15.            
  16.         }
  17.     }
  18. }
  19.   class Bank
  20.     {
  21.         List<Person> personList = new List<Person>();
  22.        
  23.         public void Welcome()
  24.         {
  25.             Console.WriteLine("Welcome to the worlds best bank!\nTo logg in press [A]\nTo create new account press[B]");
  26.            
  27.            
  28.         }
  29.  
  30.         public void Choice()
  31.         {
  32.             char uChoice = char.Parse(Console.ReadLine());
  33.             switch (uChoice)
  34.             {
  35.                 case 'A':
  36.                     Console.Clear();
  37.                     Console.WriteLine("Enter your username\n");
  38.                     string uName = Console.ReadLine();
  39.                     Console.WriteLine("Enter your password\n");
  40.                     string uPass = Console.ReadLine();
  41.  
  42.                     break;
  43.  
  44.                 case 'B':
  45.                     Console.Clear();
  46.                     Console.WriteLine("Enter username of your choice");
  47.                     string nName = Console.ReadLine();
  48.                     Console.WriteLine("Enter password of your choice");
  49.                     string nPass = Console.ReadLine();
  50.  
  51.  
  52.                     break;
  53.  
  54.             }
  55.         }
  56.         public void BankChoice()
  57.         {
  58.             Account acc = new Account();                               // User meny för det olika valen
  59.             Console.WriteLine("To check your balance press [B]\n");
  60.             Console.WriteLine("To Deposit money press [D]\n");
  61.             Console.WriteLine("To Withdraw money press [W]\n");
  62.             Console.WriteLine("To quit the application press [Q]\n");
  63.             char bankChoise = char.Parse(Console.ReadLine());
  64.  
  65.             switch (bankChoise) // Kollar kontots summa +- deposits och withdraws.
  66.             {
  67.                 case 'B':
  68.                     Console.WriteLine("Your account balance is {0}"+acc.GetBalance());
  69.                     break;
  70.                 case 'D':
  71.                     Console.WriteLine("How much money do you want to deposit?");
  72.                     int deposit = int.Parse(Console.ReadLine());
  73.                     Console.WriteLine("Your new balance is"+ acc.GetBalance(), + deposit);
  74.                     break;
  75.                 case 'W':
  76.                     Console.WriteLine("How much do you want to withdraw?");
  77.                     int withdraw = int.Parse(Console.ReadLine());
  78.                     Console.WriteLine("Your new balance is"+ acc.GetBalance(),- withdraw);
  79.                     break;
  80.             }
  81.         }
  82.         public Bank()
  83.         {
  84.             personList.Add(new Person("sture", "1234")); // Lägger till en användare som redan ska finnas i banksystemet!
  85.             for (int i = 0; i < 100; i++) // lägger till 100 personer i listan för att testköra att listan fungerar.
  86.             {
  87.                 personList.Add(new Person("Person" + i, "" + i));
  88.             }
  89.            
  90.         }
  91.         public void AddPerson()
  92.         {
  93.             Console.WriteLine("Enter username\n"); // Låter användaren skriva in sitt username och password.
  94.             string name = Console.ReadLine();
  95.             Console.WriteLine("Enter password\n");
  96.             string pass = Console.ReadLine();
  97.  
  98.             Person p = new Person(name, pass); // lägger till den nya personen i listan.
  99.             personList.Add(p);
  100.         }
  101.        
  102.     }
  103. }
  104.   class Person
  105.     {
  106.         private string userName;
  107.         private string pass;
  108.         private Account acc;
  109.         public Person(string name, string pass) // skapar vi en person som ska kunna kolla sin balance, ta ut och sätta in pengar.
  110.         {
  111.             this.userName = name;
  112.             this.pass = pass;
  113.             acc = new Account();
  114.         }
  115.         public int GetBalance()
  116.         {
  117.             return acc.GetBalance();
  118.         }
  119.  
  120.         public void Deposit(int dep)
  121.         {
  122.             acc.Deposit(dep);
  123.         }
  124.        
  125.         public void Withdraw(int draw)
  126.         {
  127.             acc.Withdraw(draw);
  128.         }
  129.  
  130.         public bool Checkpass(string input)
  131.         {
  132.             return userName == input;
  133.         }
  134.      
  135.     }
  136. }
  137.  class Account
  138.     {
  139.         private int balance;
  140.  
  141.         public Account() // Konstruktor innehåller ej returvärde som tex "Void" ska alltid heta samma som klassen!
  142.         {
  143.             balance = 5000;
  144.         }
  145.  
  146.         public int GetBalance()
  147.         {
  148.             return balance;
  149.         }
  150.  
  151.         public void Deposit(int dep)
  152.         {
  153.             balance += dep;
  154.         }
  155.  
  156.         public void Withdraw(int with)
  157.         {
  158.             balance -= with;
  159.             if(balance >= with) // om withdraw är större än summan så får du inga pengar.
  160.             {
  161.                 Console.WriteLine("No moneyz");
  162.             }
  163.         }
  164.  
  165.        
  166.    
  167.  
  168.     }
  169.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement