Need C# not java. Thanks Create a BankAccount class that can be used to maintain
ID: 3757945 • Letter: N
Question
Need C# not java. Thanks
Create a BankAccount class that can be used to maintain a bank account balance. Its constructors, properties, and methods should throw a NegativeException if there is an attempt to take the balance below zero or if there is an attempt to deposit or withdraw a negative amount. Write the NegativeException class to extend the ApplicationException class to include the additional functionality of a new message detailing the error being sent when the exception is thrown. Write an application class and test the exception-handling techniques.
Explanation / Answer
I have some basic skelten program for java it is not completed fully ..you may can add or update the java source code..
public class BankAccount {
private double balance;
public BankAccount() {
balance = 0.0;
}
public void withdraw(double amount) throws NegativeWithdraw, NotEnoughBalance {
if (amount < 0)
throw new NegativeWithdraw(amount);
else if (amount > balance)
throw new NotEnoughBalance(amount);
balance -= amount;
}
public void setBalance(String str) {
balance = Double.parseDouble(str);
}
public double getBalance() {
return balance;
}
public static void main(String[] args)
{
double passNegative = -100;
try {
new BankAccount().withdraw(passNegative);
}
catch(NegativeWithdraw | NotEnoughBalance e)
{
System.out.println(e.getMessage());
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.