Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication3
  7. {
  8.     class Program
  9.     {
  10.        public class Osoba
  11.         {
  12.             public string imie;
  13.             public string nazwisko;
  14.         }
  15.  
  16.         //pola, właściwości
  17.         public Osoba wlasciciel;
  18.         private decimal saldo = 0;
  19.         private int pin = 0;
  20.        
  21.         //metody
  22.         //sprawdzenie poprawności pinu
  23.         private bool sparwdzPin(int pin) //private bo będzie wykorzystywana w innych metodach
  24.         {
  25.             if (this.pin == pin)
  26.                 return true;
  27.             return false;
  28.         }
  29.  
  30.         public void Wplata(int kwota)
  31.         {
  32.             if (kwota < 0)//jesli podam kwotę mniejszą od 0
  33.                 throw new ArgumentException("podaj kwotę większą od 0"); //to pokaże się okno z komunikatem
  34.             saldo = saldo + kwota;  //saldo+=kwota;
  35.         }
  36.  
  37.         public string Wyplata(int kwota, int pin)
  38.         {
  39.           if (kwota < saldo && sparwdzPin(pin))
  40.             {
  41.                 saldo = saldo - kwota; //saldo-=kwota;
  42.                 return "udalo sie";
  43.             }
  44.            return "brak srodkow lub bledny pin";
  45.         }
  46.  
  47.         public bool zmienPin(int nowy, int stary)
  48.         {
  49.             if (sparwdzPin(stary))
  50.             {
  51.                 pin = nowy;
  52.                 return true;
  53.             }
  54.             return false;
  55.         }
  56.  
  57.         public string Info(int pin)
  58.         {
  59.             if (sparwdzPin(pin))
  60.                 return string.Format("imie:{0} nazwisko:{1} saldo:{2} pin:{3}", wlasciciel.imie, wlasciciel.nazwisko, saldo, pin);
  61.             return "zly pin";
  62.         }
  63.  
  64.         static void Main(string[] args)
  65.         {
  66.             Program[] klient = new Program[2];
  67.             klient[0]= new Program();
  68.             klient[1] = new Program();
  69.  
  70.             klient[0].wlasciciel = new Osoba();
  71.             klient[1].wlasciciel = new Osoba();
  72.  
  73.             klient[0].wlasciciel.imie = "Jan";
  74.             klient[0].wlasciciel.nazwisko = "Kowalski";
  75.  
  76.             //wprowadzanie narzucone
  77.             Console.WriteLine(klient[0].Info(0));
  78.             klient[0].Wplata(1000);
  79.             Console.WriteLine(klient[0].Info(0));
  80.             klient[0].Wyplata(200,0);
  81.             Console.WriteLine(klient[0].Info(0));
  82.             klient[0].zmienPin(1234, 0);
  83.             Console.WriteLine(klient[0].Info(1234));
  84.  
  85.             //wprowadzanie z klawiatury
  86.             Console.WriteLine("podaj imie i nazwisko");
  87.             klient[1].wlasciciel.imie = Console.ReadLine();
  88.             klient[1].wlasciciel.nazwisko = Console.ReadLine();
  89.  
  90.             Console.WriteLine("twoje dane:");
  91.             Console.WriteLine(klient[1].Info(0));
  92.  
  93.             Console.WriteLine("ile chcesz wplacic?");
  94.             klient[1].Wplata(Convert.ToInt16(Console.ReadLine()));
  95.             Console.WriteLine("twoje dane:");
  96.             Console.WriteLine(klient[1].Info(0));
  97.  
  98.             Console.WriteLine("ile chcesz wyplacic?");
  99.             klient[1].Wyplata(Convert.ToInt16(Console.ReadLine()), 0);
  100.  
  101.             Console.WriteLine("twoje dane:");
  102.             Console.WriteLine(klient[1].Info(0));
  103.  
  104.             Console.WriteLine("podaj nowy i stary pin");
  105.             klient[1].zmienPin(Convert.ToInt16(Console.ReadLine()),Convert.ToInt16(Console.ReadLine()));
  106.  
  107.             Console.WriteLine("podaj nowy pin");
  108.             Console.WriteLine(klient[1].Info(Convert.ToInt16(Console.ReadLine())));
  109.  
  110.  
  111.            
  112.  
  113.             Console.Read();
  114.         }
  115.     }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement