· 4 years ago · May 11, 2021, 12:58 PM
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6
7namespace Pilarski_Maciej_55217_Projektowanie_Obiektowe_LAB
8{
9 class Program
10 {
11 static void Main(string[] args)
12 {
13 //------------------------------------------------------
14 //----------- Podpowiedzi w zadaniach ------------------
15 //
16 // Zajęcia 9 - klasa bankier uczciwy i fałszywy
17 // Zajęcia 4 - dodawanie do koszyka (jak do konta pieniędzy)
18 //------------------------------------------------------
19 // ---------------- Treść zadania ----------------------
20 //
21 // Dwa panele: użytkownik i admin
22 //
23 // ------- Użytkownik: -------
24 // -wpłaca i wypłaca,
25 // -sprawdza historię operacji na koncie,
26 // -generuje podsumowanie: ile wpłacił i ile wypłacił od początku
27 // -może wziąć kredyt(pole kredyt w klasie Konto), ALE TYLKO JEDEN.Metoda SpłaćKredyt przelewa pieniądze z konta na spłatę kredytu.
28 // -może zrobić przelew na inne konto
29 // -wszystkie operacje możliwe dopiero po zalogowaniu na konto(hasło przechowujemy w klasie Account)
30 //
31 // ------- Admin -------
32 // -może zabokować konto użytkownikowi(pole typu bool w Account), wtedy użytkownik nie może się zalogować
33 // -może dodawać i usuwać konta
34 // -może robić podsumowania: ile w sumie jest pieniędzy w banku, ile wynosi łączny kredyt itd
35 // -jest w posiadaniu historii kredytowej każdego klienta, może też pobrać wszystkich aktualnych dłużników
36 //
37 // ------- Klasy: -------
38 // Account, Bank(pole: tablica / kolekcja kont)
39 // konta w banku przechowujemy w kolekcji ArrayList
40 //
41 //
42 // kontakt: 80rass @gmail.com
43
44
45
46 // ================================== PROGRAM ==================================
47 // =============================================================================
48
49 Account Informatyk = new Account(1, "12345");
50 Account Klient = new Account(2, "54321");
51
52
53 // Lista opcji:
54 // XXX.Info() - podaje informacje o danym użytkowniku
55 // XXX.Deposit($$$) - wpłaca pieniądze na konto
56 // XXX.Withdraw($$$) - wypłaca pieniadze z konta
57 // XX1.TransferMoney(XX2, $$$)
58 // XXX.TakeCredit - bierze kredyt
59 // XXX.History - wyświetla: wzięte kredyty, wpłaty i wypłaty w danej kolejności wykonywania
60 // XXX.Sum - podaje łączną wartość wpłat i wypłat
61 // XXX.Ban - blokuje konto
62 // XXX.unBan - odblokowuje konto
63
64
65 Informatyk.Info(); // info początkowe - świeze konta:
66 Klient.Info();
67 Informatyk.Deposit(5000); // Wpłacamy pierwsze pieniądze
68 Informatyk.Deposit(3000);
69 Klient.Deposit(1000);
70 Informatyk.Info(); // stan kont po wpłatach
71 Klient.Info();
72 Informatyk.Withdraw(1500); // wypłacamy pieniądze
73 Klient.Withdraw(1500); // chce wypłacić więcej niż może
74 Informatyk.Info(); // info po wypłatach
75 Klient.Info();
76 Console.WriteLine("Zlecamy Przelew z Informatyka na klienta");
77 Informatyk.TransferMoney(Klient, 500); // przelewamy z Informatyka na klienta
78 Informatyk.Info(); // info po przelewie
79 Klient.Info();
80 Informatyk.TakeCredit(5000); // informatyk bierze kredyt
81 Console.WriteLine("Wyświetlamy historie informatyka:");
82 Informatyk.History(); // wyświetlamy historię
83 Console.WriteLine("Wyświetlamy sumy wpłąt i wypłat informatyka:");
84 Informatyk.Sum(); // wyświetlamy sumę wpłat i wypłat
85 Informatyk.PayCredit(); // Informatyk spłaca kredyt
86 Klient.PayCredit(); // informatyk stara się spłacić kredyt nie mając kredytu
87 Klient.TakeCredit(2000); // Klient bierze kredyt
88 Klient.Withdraw(2000); // wypłaca kredyt
89 Klient.PayCredit(); // stara się spłacić kredyt bez pieniędzy
90 Informatyk.Ban(); // banujemy informatyka
91 Informatyk.Info(); // info po banie
92 Klient.Info();
93 Informatyk.unBan();
94 Informatyk.Info(); // info po odbanowaniu
95 Klient.Info();
96
97
98
99
100
101 // za pomocą banku:
102 Console.WriteLine("=================================================================");
103 Console.WriteLine("=================================================================");
104 Console.WriteLine("Tworzymy konta o ID 10, 11, 12"); // tworzymy konta
105
106 Bank bank = new Bank();
107 bank.CreateAccount(10, "123");
108 bank.CreateAccount(11, "456");
109 bank.CreateAccount(12, "789");
110
111 Console.WriteLine(bank);
112 Console.WriteLine("----------------------------------------------------------------");
113 bank.account1.Deposit(2000); // wpłata na konto1 ID 10
114 bank.account2.Deposit(2000); // wpłata na konto2 ID 11
115 bank.account3.Deposit(2000); // wpłata na konto3 ID 12
116 bank.Ban(11); // Ban na konto3 ID 12
117 bank.DeleteAccount(12); // usuwamy konto2 ID 11
118 bank.account1.TakeCredit(3000); // bierzemy kredyt konto1 ID 10
119 bank.ShowCreditHistory(10); // wyświetlamy historię konto1 ID 10
120 Console.WriteLine("----------------------------------------------------------------");
121 Console.WriteLine(bank);
122 Console.ReadLine();
123 }
124 }
125}
126=============================================================================================================================
127=============================================================================================================================
128=============================================================================================================================
129using System;
130using System.Collections;
131using System.Collections.Generic;
132using System.Linq;
133using System.Text;
134using System.Threading.Tasks;
135
136namespace Pilarski_Maciej_55217_Projektowanie_Obiektowe_LAB
137{
138 class Account
139 {
140 // ================================ KLASA KONTO ================================
141 // =============================================================================
142
143 // konstruktor klasy konto (Account)
144 private string password;
145 private int id, balance, balance_prev, deposit, withdrawall, credit;
146 private bool isCredit;
147 public bool isBanned;
148
149 public Account(int id, string password)
150 {
151 this.id = id;
152 this.password = password;
153 balance = 0;
154 deposit = 0;
155 withdrawall = 0;
156 isCredit = false;
157 isBanned = false;
158 }
159
160 public Account(int id)
161 {
162 this.id = id;
163 }
164
165 public int GetId()
166 {
167 return this.id;
168 }
169
170 public int GetCredit()
171 {
172 return credit;
173 }
174
175
176 // =================== Metody klasy konto (void'y Account'a) ===================
177
178 // 1. Wpłacenie pieniędzy
179 public void Deposit(int cashin)
180 {
181 balance_prev = balance;
182 this.balance += cashin;
183 list.Add(this.balance - balance_prev);
184 deposit += cashin;
185 Console.WriteLine("Wpłaciłeś :" + cashin + "PLN do konta o id: " + id);
186 }
187
188 // 2. Wypłacenie pieniędzy
189 public void Withdraw(int cashout)
190 {
191 if (balance - cashout >= 0)
192 {
193 balance_prev = balance;
194 this.balance -= cashout;
195 list.Add(this.balance - balance_prev);
196 withdrawall += cashout;
197 Console.WriteLine("Wypłaciłeś :" + cashout + "PLN z konta o id: " + id);
198 }
199 else
200 {
201 Console.WriteLine("Nie masz wystarczająco środków na koncie");
202 }
203 }
204
205 // 3. Informacje o koncie - nie działa
206 public void Info()
207 {
208 Console.WriteLine("------------------------------");
209 Console.WriteLine("Właściciel: " + id); // podanie ID
210 Console.WriteLine("Stan konta: " + balance + "PLN"); // wyświetlenie salda
211 Console.Write("Kredyt: "); // wyświetlenie czy ma kredyt
212 if (isCredit == true)
213 Console.WriteLine("Posiada kredyt");
214 else
215 {
216 Console.WriteLine("Nie posiada kredytu");
217 };
218 Console.WriteLine("Kwota kredytu: " + credit + "PLN"); // wyświetlenie kwoty kredytu
219 Console.Write("Aktywność konta: ");
220 if (isBanned == true)
221 Console.WriteLine("Zablokowane");
222 else
223 {
224 Console.WriteLine("Aktywne");
225 };
226 Console.WriteLine("------------------------------");
227 }
228
229 // 4. Sprawdź historię operacji na koncie
230 public void History()
231 {
232 Console.WriteLine("///////////");
233 if (isCredit)
234 Console.WriteLine("Kwota kredytu: " + credit + "PLN");
235
236 Console.WriteLine("Transakcje:");
237 foreach (int change in list)
238 {
239 if (change > 0)
240 Console.WriteLine("Wpłaty: " + change);
241
242 if (change <= 0)
243 Console.WriteLine("Wypłaty: " + change);
244 }
245 Console.WriteLine("///////////");
246 }
247
248 // 5. Suma wszystkich wpłat i wypłąt na konto
249 public void Sum()
250 {
251 Console.WriteLine("Suma wpłat " + deposit);
252 Console.WriteLine("Suma wypłat " + withdrawall);
253 }
254
255 // 6. Weź kredyt
256 public void TakeCredit(int credit)
257 {
258 if (!isCredit)
259 {
260 this.credit = credit;
261 this.balance += credit;
262 Console.WriteLine("Pobrano kredyt o kwocie: " + credit + ". Twoje aktualne saldo to: " + this.balance);
263 isCredit = true;
264 }
265 else
266 {
267 Console.WriteLine("Przed wzięciem kolejnego kredytu, musisz opłacić obecny");
268 }
269 }
270
271 // 7. Spłać kredyt
272 public void PayCredit()
273 {
274 if (isCredit && this.balance >= this.credit)
275 {
276 this.balance -= this.credit;
277 Console.WriteLine("Spłacono kredyt o kwocie: " + this.credit + ". Twoje aktualne saldo to: " + this.balance);
278 isCredit = false;
279 }
280 else if (isCredit && this.balance < this.credit)
281 {
282 Console.WriteLine("Nie masz odpowiednich środków do spłacenia kredytu.");
283 }
284 else
285 {
286 Console.WriteLine("Nie masz kredytu do spłacenia.");
287 }
288 }
289
290 // 8. Przelej pieniądze na inne konto
291 public void TransferMoney(Account account, int amount)
292 {
293 if (account != null && amount <= this.balance)
294 {
295 this.balance -= amount;
296 account.balance += amount;
297 }
298
299 }
300
301 // 9. Zablokuj konto
302 public void Ban()
303 {
304 isBanned = true;
305 }
306
307 // 10. Odblokowanie konta
308 public void unBan()
309 {
310 isBanned = false;
311 }
312 ArrayList list = new ArrayList();
313
314 }
315}
316=============================================================================================================================
317=============================================================================================================================
318=============================================================================================================================
319using System;
320using System.Collections.Generic;
321using System.Linq;
322using System.Text;
323using System.Threading.Tasks;
324
325namespace Pilarski_Maciej_55217_Projektowanie_Obiektowe_LAB
326{
327 class Bank
328 {
329
330 // ================================== KLASA BANK ==================================
331 // ================================================================================
332
333 // konstruktor klasy bank (Bank)
334 public Account account1, account2, account3;
335
336 public Bank()
337 {
338 account1 = null;
339 account2 = null;
340 account3 = null;
341 }
342
343 // ===================== Metody klasy bank (void'y Bank'u) =====================
344
345 // 1. Wpłaty
346 public void Deposit(int id, int cashin)
347 {
348 if (account1 != null && account1.GetId() == id)
349 account1.Deposit(cashin);
350 else if (account2 != null && account2.GetId() == id)
351 account2.Deposit(cashin);
352 else if (account3 != null && account3.GetId() == id)
353 account3.Deposit(cashin);
354
355 }
356
357 // 2. Wypłaty
358 public void Withdraw(int id, int cashout)
359 {
360 if (account1 != null && account1.GetId() == id)
361 account1.Withdraw(cashout);
362 else if (account2 != null && account2.GetId() == id)
363 account2.Withdraw(cashout);
364 else if (account3 != null && account3.GetId() == id)
365 account3.Withdraw(cashout);
366 }
367
368 // 3. Stwórz konto - dodaj użytkownika
369 public void CreateAccount(int id, string password)
370 {
371 Account account = new Account(id, password);
372
373 if (account1 == null)
374 account1 = account;
375 else if (account2 == null)
376 account2 = account;
377 else if (account3 == null)
378 account3 = account;
379 }
380
381 // 4. Usuń użytkownika
382 public void DeleteAccount(int id)
383 {
384 if (account1 != null && account1.GetId() == id)
385 {
386 account1 = null;
387 Console.WriteLine("Twoje konto o ID: " + id + " zostało usunięte");
388 }
389 else if (account2 != null && account2.GetId() == id)
390 {
391 account2 = null;
392 Console.WriteLine("Twoje konto o ID: " + id + " zostało usunięte");
393 }
394 else if (account3 != null && account3.GetId() == id)
395 {
396 account3 = null;
397 Console.WriteLine("Twoje konto o ID: " + id + " zostało usunięte");
398 }
399 }
400
401 // 5. Zablokuj użytkownika
402 public void Ban(int id)
403 {
404
405 if (account1 != null && account1.GetId() == id)
406 {
407 account1.isBanned = true;
408 Console.WriteLine($"Konto {id} zostało zablokowane");
409 }
410
411 else if (account2 != null && account2.GetId() == id)
412 {
413 account1.isBanned = true;
414 Console.WriteLine($"Konto {id} zostało zablokowane");
415 }
416 else if (account3 != null && account3.GetId() == id)
417 {
418 account1.isBanned = true;
419 Console.WriteLine($"Konto {id} zostało zablokowane");
420 }
421 }
422
423 // 6. Pokaż historie kredytów
424 public void ShowCreditHistory(int id)
425 {
426 Account account = new Account(id);
427
428 Console.WriteLine("Lista dłużników: ");
429 if (account1 != null && account1.GetId() == id)
430 Console.WriteLine($"Konto {id}. Kwota: {account1.GetCredit()}");
431 else if (account2 != null && account2.GetId() == id)
432 Console.WriteLine($"Konto {id}. Kwota: {account2.GetCredit()}");
433 else if (account3 != null && account3.GetId() == id)
434 Console.WriteLine($"Konto {id}. Kwota: {account3.GetCredit()}");
435
436 }
437
438 public override string ToString()
439 {
440 string description1 = account1 == null ? "brak konta" : account1.ToString();
441 string description2 = account2 == null ? "brak konta" : account2.ToString();
442 string description3 = account3 == null ? "brak konta" : account3.ToString();
443
444 return $"konto1 = {description1}, konto2 = {description2}, konto3 = {description3} ";
445 }
446
447 }
448}