Advertisement
Guest User

Untitled

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