Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // KLASA LIB
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Konto
- {
- public class Konto
- {
- public class Osoba
- {
- public Osoba() { }
- public Osoba(string im, string na) { Imie = im; Nazwisko = na; }
- private string Imie;
- private string Nazwisko;
- public string getOsoba()
- {
- return Imie + ' ' + Nazwisko;
- }
- }
- public Konto() { }
- public Konto(string imie, string nazwisko, decimal sal, int pin) { Saldo = sal; Pin = pin; Wlasciciel = new Osoba(imie, nazwisko); }
- public Osoba Wlasciciel;
- private decimal Saldo { get; set; }
- private int Pin { get; set; }
- public void AddCash(int x)
- {
- Saldo = Saldo + x;
- }
- public string TakeCash(int x, int pin)
- {
- if (InputPin(pin) == true)
- {
- if (Saldo > x)
- {
- Saldo = Saldo - x;
- return "OPERACJA WYKONANA POPRAWNIE. Nowy stan: " + Saldo.ToString();
- }
- else throw new Exception("OPERACJA ANULOWANA");
- }
- else throw new Exception("Błąd pinu");
- }
- public string CheckSaldo(int pin)
- {
- if (InputPin(pin) == true)
- {
- return Saldo.ToString();
- }
- else throw new Exception("Błąd pinu");
- }
- public void SetPin(int x)
- {
- Pin = x;
- }
- public bool InputPin(int x)
- {
- if (x == Pin)
- {
- return true;
- }
- else return false;
- }
- public int getPin()
- {
- return Pin;
- }
- public string getInfo()
- {
- return "Imię i Nazwisko : " + Wlasciciel.getOsoba() + "\r\n" + " Saldo Konta : " + Saldo.ToString() + "\r\n" + "Aktualny PIN : " + Pin.ToString();
- }
- }
- }
- // PROG GL
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace KontoKonsole
- {
- class Program
- {
- static void Main(string[] args)
- {
- Konto.Konto a = new Konto.Konto("Jan", "Kowalski", 110, 3333);
- int pin;
- pin = int.Parse(Console.ReadLine());
- try
- {
- Console.WriteLine(String.Format(a.CheckSaldo(pin)));
- }
- catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- }
- Console.WriteLine(a.Wlasciciel.getOsoba());
- try
- {
- Console.WriteLine(a.TakeCash(100, 3333));
- }
- catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement