Question: In this task, youre going to be created a new Bank class in a file named Bank.cs. This will be used to play the role
In this task, youre going to be created a new Bank class in a file named Bank.cs. This will be used to play the role of the Bank, which will have a number of accounts that it manages. To start off, lets add a the Bank class. 1. Create a new C# file named bank.cs. , in it, add the Bank class which meets the following UML 2. Implement the AddAcount , and GetAccount methods: AddAccount: Add the account which is passed in, into the Banks list of accounts. To do this, using the argument. Add method on the accounts object, and pass in the GetAccount: Iterate through _accounts, and return the first bank which has the same name as the passed in name parameter. Note: If the list of accounts doesnt have a matching account, you will need to return null. The null value is a special marker that indicates no object. So in this case, we are returning no account object as there are none with the required name. Note: To get this working you will need to add a readonly Name property to the Account class. The get method for this will return the value from name field. Users of GetAccount will then have to check if they got an account or no account ( null) when they called GetAccount. Here is the pseudocode for how we can find an account. Loop for each account If the current account has the matching name Return the current account After the loop return null as no account had a matching name 3. Notice in the UML diagram, ExecuteTransaction is listed three times but with different parameters. This is known as Method Overloading. When the ExecuteTransaction method is called, the correct method is identified by determining the type of the argument which is being passed in. As you can see, we accept the types WithdrawTransaction DepositTransaction, and TransferTransaction. The bodies of each ExecuteTransaction methods are the same, they call Execute on the transaction parameter. 4. Now that weve got this Bank class, we need to refactor Main to use it! In Main, add a new Bank object. Add new menuoption values - NewAccount and the code so that the user can see, select, and run this option. It will: Ask the user for the name of the account and its starting balance Create a new Account object Use the AddAccount method on the bank object to add the new account. 5. Next, we need a way of getting the account(s) for the other menu options. To do this we can add a static method in the FindAccount. This can be implemented as shown below. public class Program { //... private static Account FindAccount(Bank fromBank) { Console.Write("Enter account name: "); String name = Console.ReadLine(); Account result = fromBank.GetAccount(name); if ( result == null ) { Console.WriteLine($"No account found with name {name}"); } return result; } } 6. Change DoDeposit to make use of the Bank. You need to change the parameters to be passed a Bank object, not an account object. DoDeposit can then use the Bank to find the account to deposit to. Here is a start for this code, with some comments for guidance: private static void DoDeposit(Bank toBank) { Account toAccount = FindAccount(toBank); if (toAccount == null) return; // Read in the amount // Create the Deposit transaction // Tell toBank to run the transaction // Ask the transaction to Print } 7. Compile and run your program and make sure you can create an account, and deposit money into it. 8. Make similar changes to the DoWithdraw and DoTransfer methods. With Transfer, you will need to find both the from and to accounts, and you want to make sure that neither is null.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
