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;
- namespace ConsoleApplication3
- {
- class Program
- {
- public class Osoba
- {
- public string imie;
- public string nazwisko;
- }
- //pola, właściwości
- public Osoba wlasciciel;
- private decimal saldo = 0;
- private int pin = 0;
- //metody
- //sprawdzenie poprawności pinu
- private bool sparwdzPin(int pin) //private bo będzie wykorzystywana w innych metodach
- {
- if (this.pin == pin)
- return true;
- return false;
- }
- public void Wplata(int kwota)
- {
- if (kwota < 0)//jesli podam kwotę mniejszą od 0
- throw new ArgumentException("podaj kwotę większą od 0"); //to pokaże się okno z komunikatem
- saldo = saldo + kwota; //saldo+=kwota;
- }
- public string Wyplata(int kwota, int pin)
- {
- if (kwota < saldo && sparwdzPin(pin))
- {
- saldo = saldo - kwota; //saldo-=kwota;
- return "udalo sie";
- }
- return "brak srodkow lub bledny pin";
- }
- public bool zmienPin(int nowy, int stary)
- {
- if (sparwdzPin(stary))
- {
- pin = nowy;
- return true;
- }
- return false;
- }
- public string Info(int pin)
- {
- if (sparwdzPin(pin))
- return string.Format("imie:{0} nazwisko:{1} saldo:{2} pin:{3}", wlasciciel.imie, wlasciciel.nazwisko, saldo, pin);
- return "zly pin";
- }
- static void Main(string[] args)
- {
- Program[] klient = new Program[2];
- klient[0]= new Program();
- klient[1] = new Program();
- klient[0].wlasciciel = new Osoba();
- klient[1].wlasciciel = new Osoba();
- klient[0].wlasciciel.imie = "Jan";
- klient[0].wlasciciel.nazwisko = "Kowalski";
- //wprowadzanie narzucone
- Console.WriteLine(klient[0].Info(0));
- klient[0].Wplata(1000);
- Console.WriteLine(klient[0].Info(0));
- klient[0].Wyplata(200,0);
- Console.WriteLine(klient[0].Info(0));
- klient[0].zmienPin(1234, 0);
- Console.WriteLine(klient[0].Info(1234));
- //wprowadzanie z klawiatury
- Console.WriteLine("podaj imie i nazwisko");
- klient[1].wlasciciel.imie = Console.ReadLine();
- klient[1].wlasciciel.nazwisko = Console.ReadLine();
- Console.WriteLine("twoje dane:");
- Console.WriteLine(klient[1].Info(0));
- Console.WriteLine("ile chcesz wplacic?");
- klient[1].Wplata(Convert.ToInt16(Console.ReadLine()));
- Console.WriteLine("twoje dane:");
- Console.WriteLine(klient[1].Info(0));
- Console.WriteLine("ile chcesz wyplacic?");
- klient[1].Wyplata(Convert.ToInt16(Console.ReadLine()), 0);
- Console.WriteLine("twoje dane:");
- Console.WriteLine(klient[1].Info(0));
- Console.WriteLine("podaj nowy i stary pin");
- klient[1].zmienPin(Convert.ToInt16(Console.ReadLine()),Convert.ToInt16(Console.ReadLine()));
- Console.WriteLine("podaj nowy pin");
- Console.WriteLine(klient[1].Info(Convert.ToInt16(Console.ReadLine())));
- Console.Read();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement