Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace BankÖvning
- {
- class Program
- {
- static void Main(string[] args)
- {
- Account acc = new Account();
- Bank bank = new Bank();
- Person person = new Person("name","pass");
- }
- }
- }
- class Person
- {
- private string userName;
- private string pass;
- private Account acc;
- public Person(string name, string pass) // skapar vi en person som ska kunna kolla sin balance, ta ut och sätta in pengar.
- {
- this.userName = name;
- this.pass = pass;
- acc = new Account();
- }
- public int GetBalance()
- {
- return acc.GetBalance();
- }
- public void Deposit(int dep)
- {
- acc.Deposit(dep);
- }
- public void Withdraw(int draw)
- {
- acc.Withdraw(draw);
- }
- public bool Checkpass(string input)
- {
- return userName == input;
- }
- }
- }
- class Account
- {
- private int balance;
- public Account() // Konstruktor innehåller ej returvärde som tex "Void" ska alltid heta samma som klassen!
- {
- balance = 5000;
- }
- public int GetBalance()
- {
- return balance;
- }
- public void Deposit(int dep)
- {
- balance += dep;
- }
- public void Withdraw(int with)
- {
- if(balance >= with)
- { balance -= with;
- }
- else // om withdraw är större än summan så får du inga pengar.
- {
- Console.WriteLine("No moneyz");
- }
- }
- }
- }
- class Bank
- {
- List<Person> personList = new List<Person>();
- public void Welcome()
- {
- Console.WriteLine("Welcome to the worlds best bank!\nTo logg in press [A]\nTo create new account press[B]");
- }
- public void Choice()
- {
- char uChoice = char.Parse(Console.ReadLine());
- switch (uChoice)
- {
- case 'A':
- Console.Clear();
- Console.WriteLine("Enter your username\n");
- string uName = Console.ReadLine();
- Console.WriteLine("Enter your password\n");
- string uPass = Console.ReadLine();
- break;
- case 'B':
- Console.Clear();
- Console.WriteLine("Enter username of your choice");
- string nName = Console.ReadLine();
- Console.WriteLine("Enter password of your choice");
- string nPass = Console.ReadLine();
- break;
- }
- }
- public void BankChoice()
- {
- Account acc = new Account(); // User meny för det olika valen
- Console.WriteLine("To check your balance press [B]\n");
- Console.WriteLine("To Deposit money press [D]\n");
- Console.WriteLine("To Withdraw money press [W]\n");
- Console.WriteLine("To quit the application press [Q]\n");
- char bankChoise = char.Parse(Console.ReadLine());
- switch (bankChoise) // Kollar kontots summa +- deposits och withdraws.
- {
- case 'B':
- Console.WriteLine("Your account balance is {0}"+acc.GetBalance());
- break;
- case 'D':
- Console.WriteLine("How much money do you want to deposit?");
- int deposit = int.Parse(Console.ReadLine());
- Console.WriteLine("Your new balance is"+ acc.GetBalance(), + deposit);
- break;
- case 'W':
- Console.WriteLine("How much do you want to withdraw?");
- int withdraw = int.Parse(Console.ReadLine());
- Console.WriteLine("Your new balance is"+ acc.GetBalance(),- withdraw);
- break;
- }
- }
- public Bank()
- {
- personList.Add(new Person("sture", "1234")); // Lägger till en användare som redan ska finnas i banksystemet!
- for (int i = 0; i < 100; i++) // lägger till 100 personer i listan för att testköra att listan fungerar.
- {
- personList.Add(new Person("Person" + i, "" + i));
- }
- }
- public void AddPerson()
- {
- Console.WriteLine("Enter username\n"); // Låter användaren skriva in sitt username och password.
- string name = Console.ReadLine();
- Console.WriteLine("Enter password\n");
- string pass = Console.ReadLine();
- Person p = new Person(name, pass); // lägger till den nya personen i listan.
- personList.Add(p);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement