Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

To be done in c#. I can't get my code (below) to execute the exceptions! 1- First, the bank account is empty. 2- 1500 deposit

To be done in c#. I can't get my code (below) to execute the exceptions!

1- First, the bank account is empty. 2- 1500 deposit is made 3- Attempt to withdraw 1050 but the overdraft limit is 1000 4- Since the the amount to withdraw is greater than the overdraft limit the OverdraftEx exception should display my message (but it is not). 5- Then an attempt to withdraw 1000 which should be successful and the balance should become 500 6- Now, an attempt to withdraw 50 but second exception message DailyLimitEx should display which is exceeding the daily limit, because the Daily withdraw limit is 1000 and it has already been withdrawn for the day, again this exception is not getting displayed. 7- Then, End of the Day will display which is resetting the DailyLimit back to 0. 8- Then an attempt to withdraw 50 is allowed because it is a new day. I can't get the exceptions' messages to display. Can you please help? at the end there is a sample output.

Thanks

------------------------------------------------------------

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace ConsoleApp2 { class Program { static void Main(string[] args) { Account account = new Account(); try { double overdraftLimit = 1000; double dailyWithdrawlLimit = 1000; } catch(OverdraftEx e1) { Console.WriteLine(e1.Message); } catch (DailyLimitEx e2) { Console.WriteLine(e2.Message); }

account.display(); account.deposit(1500); account.withdraw(1050); account.withdraw(1000); Console.WriteLine("-------------------"); account.withdraw(50); account.endDay(); account.withdraw(50);

Console.ReadLine(); return; } }

class OverdraftEx : Exception { private static string msg = " Sorry, the amount you are trying to withdraw exceeds your allowed overdraft limit."; public OverdraftEx() : base(msg) { } }

class DailyLimitEx : Exception { private static string msg1 = " Sorry, you have exceeded your allowed daily withdrawal limit."; public DailyLimitEx() : base(msg1) { } }

class Account { public int accountID { get; set; } public double amount; public double balance; public double Balance { get { return balance; } set { if (amount > overdraftLimit) { OverdraftEx ex1 = new OverdraftEx(); throw ex1; } } }

public double overdraftLimit { get; set; }

public double dailyWithdrawlLimit { get { return dailyWithdrawlLimit; } set { if (amount > dailyWithdrawlLimit - 1000) { DailyLimitEx ex2 = new DailyLimitEx(); throw ex2; } } }

public Account() { accountID = 10; balance = 0; return; }

public Account(int accID, double accBalance) { accountID = accID; balance = accBalance; return; }

public void withdraw(double amount) { Console.WriteLine(""); Console.WriteLine(" Attempting to withdraw $" + Math.Round(amount, 2)); balance = balance - amount;

Console.WriteLine(" Account #: " + accountID); Console.WriteLine(" Your new balance is $" + Math.Round(balance, 2)); }

public void deposit(double amount) { // calculating the balance after depositing money

if (amount > 0) { Console.WriteLine(" Depositing $" + Math.Round(amount, 2)); balance = balance + amount; Console.WriteLine(" Account #: " + accountID); Console.WriteLine(" Balance: $" + Math.Round(balance, 2)); } else Console.WriteLine(" Sorry, amount is invalid");

Console.WriteLine(""); return; }

public void display() { Console.WriteLine(""); Console.WriteLine(" Account ID: " + accountID); Console.WriteLine(" Balance: $" + Math.Round(balance, 2)); Console.WriteLine("");

return; } public void endDay() { Console.WriteLine(""); Console.WriteLine(" End Day"); Console.WriteLine(" Account ID: " + accountID); Console.WriteLine(" Balance: $" + Math.Round(balance, 2)); return; } }

} ---------------------------------------------------------------------

Sample output: Note: the first error message should display: "Sorry, the amount you are trying to withdraw exceeds your allowed overdraft limit" not what is displayed below.

image text in transcribed

Account # 10 Balance: $e.00 Depositing $15e0 Account # 10 Balance: $1,50e.00 Attemping to withdraw $105e ERROR: You have reached your limit for withdrawals for the day Account # 1 Balance: $1,500.00 Attemping to withdraw $1000 Account # 1 Balance: $500.00 Attemping to withdraw $50 ERROR: You have reached your limit for withdrawals for the day Account # 10 Balance: $500.ee End Day Account # 10 Balance: $500.ee Attemping to withdraw $5e Account # 10 Balance: $450.0e Account # 10 Balance: $e.00 Depositing $15e0 Account # 10 Balance: $1,50e.00 Attemping to withdraw $105e ERROR: You have reached your limit for withdrawals for the day Account # 1 Balance: $1,500.00 Attemping to withdraw $1000 Account # 1 Balance: $500.00 Attemping to withdraw $50 ERROR: You have reached your limit for withdrawals for the day Account # 10 Balance: $500.ee End Day Account # 10 Balance: $500.ee Attemping to withdraw $5e Account # 10 Balance: $450.0e

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions