File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 11package Bank ;
22import java .io .Serializable ;
33
4+ import Exceptions .InvalidAmount ;
45import Exceptions .MaxBalance ;
56import Exceptions .MaxWithdraw ;
67
@@ -59,4 +60,9 @@ public double getbalance()
5960 public String toString () {
6061 return "Name: " + name + ", Id: " + acc_num + ", Balance: " + balance +"Type:" +this .getClass ();
6162 }
63+
64+ public String getAccNum () {
65+ return acc_num ;
66+ }
67+
6268}
Original file line number Diff line number Diff line change 1+ package Bank ;
2+
3+ import Data .FileIO ;
4+
5+ public class RemoveAccount {
6+
7+ public static boolean removeAccount (String accNumToRemove ) {
8+ FileIO .Read (); // data dosyasından Bank objesini oku
9+ BankAccount [] accounts = FileIO .bank .getAccounts ();
10+ boolean removed = false ;
11+
12+ for (int i = 0 ; i < accounts .length ; i ++) {
13+ if (accounts [i ] != null && accounts [i ].getAccNum ().equals (accNumToRemove )) {
14+ accounts [i ] = null ; // Diziden sil
15+ removed = true ;
16+ break ;
17+ }
18+ }
19+
20+ if (removed ) {
21+ FileIO .bank .setAccounts (accounts ); // diziyi geri ata
22+ FileIO .Write (); // data dosyasına yaz
23+ System .out .println ("Account " + accNumToRemove + " removed successfully." );
24+ } else {
25+ System .out .println ("Account " + accNumToRemove + " not found." );
26+ }
27+
28+ return removed ;
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments