Advertisement
Guest User

Untitled

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