Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. // KLASA LIB
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace Konto
  10. {
  11. public class Konto
  12. {
  13. public class Osoba
  14. {
  15. public Osoba() { }
  16. public Osoba(string im, string na) { Imie = im; Nazwisko = na; }
  17. private string Imie;
  18. private string Nazwisko;
  19. public string getOsoba()
  20. {
  21. return Imie + ' ' + Nazwisko;
  22. }
  23.  
  24. }
  25. public Konto() { }
  26. public Konto(string imie, string nazwisko, decimal sal, int pin) { Saldo = sal; Pin = pin; Wlasciciel = new Osoba(imie, nazwisko); }
  27.  
  28. public Osoba Wlasciciel;
  29. private decimal Saldo { get; set; }
  30. private int Pin { get; set; }
  31.  
  32. public void AddCash(int x)
  33. {
  34. Saldo = Saldo + x;
  35. }
  36. public string TakeCash(int x, int pin)
  37. {
  38.  
  39. if (InputPin(pin) == true)
  40. {
  41. if (Saldo > x)
  42. {
  43. Saldo = Saldo - x;
  44.  
  45. return "OPERACJA WYKONANA POPRAWNIE. Nowy stan: " + Saldo.ToString();
  46. }
  47. else throw new Exception("OPERACJA ANULOWANA");
  48. }
  49. else throw new Exception("Błąd pinu");
  50.  
  51.  
  52. }
  53. public string CheckSaldo(int pin)
  54. {
  55. if (InputPin(pin) == true)
  56. {
  57. return Saldo.ToString();
  58. }
  59. else throw new Exception("Błąd pinu");
  60. }
  61. public void SetPin(int x)
  62. {
  63. Pin = x;
  64. }
  65. public bool InputPin(int x)
  66. {
  67. if (x == Pin)
  68. {
  69. return true;
  70. }
  71. else return false;
  72. }
  73. public int getPin()
  74. {
  75. return Pin;
  76. }
  77. public string getInfo()
  78. {
  79. return "Imię i Nazwisko : " + Wlasciciel.getOsoba() + "\r\n" + " Saldo Konta : " + Saldo.ToString() + "\r\n" + "Aktualny PIN : " + Pin.ToString();
  80. }
  81. }
  82.  
  83. }
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90. // PROG GL
  91.  
  92. using System;
  93. using System.Collections.Generic;
  94. using System.Linq;
  95. using System.Text;
  96. using System.Threading.Tasks;
  97.  
  98. namespace KontoKonsole
  99. {
  100. class Program
  101. {
  102. static void Main(string[] args)
  103. {
  104. Konto.Konto a = new Konto.Konto("Jan", "Kowalski", 110, 3333);
  105. int pin;
  106. pin = int.Parse(Console.ReadLine());
  107. try
  108. {
  109. Console.WriteLine(String.Format(a.CheckSaldo(pin)));
  110. }
  111. catch (Exception e)
  112. {
  113. Console.WriteLine(e.ToString());
  114. }
  115.  
  116. Console.WriteLine(a.Wlasciciel.getOsoba());
  117.  
  118. try
  119. {
  120. Console.WriteLine(a.TakeCash(100, 3333));
  121. }
  122. catch (Exception e)
  123. {
  124. Console.WriteLine(e.ToString());
  125. }
  126.  
  127. Console.ReadKey();
  128. }
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement