I have done the code but the error unreported exception InvalidWithdrawalException; must be caught or declared to be thrown
w.withDrawal(200.00, 100.00); shown
my code is
import java.util.*;
class InvalidWithdrawalException extends Exception
{
public InvalidWithdrawalException()
{
}
public InvalidWithdrawalException(
String message)
{
super(message);
}
public InvalidWithdrawalException(Throwable cause)
{
super(cause);
}
}
class AccountServer
{
double balance, withdrawal, deposit;
public static void withDrawal(double withdrawal, double balance) throws InvalidWithdrawalException
{
if(withdrawal > balance){
throw new InvalidWithdrawalException();}
}
public static void transaction(double deposit, double withdrawal, double balance) throws IllegalArgumentException
{
if (deposit <0 || withdrawal < 0)
throw new IllegalArgumentException ();
}
}
class CustomerClient
{
String customerName;
long accountNo;
double newb, balance, withdrawal, deposit;
public void customerWithdrawal()
{
try
{
AccountServer n = new AccountServer();
n.withDrawal(withdrawal, balance);
}
catch (InvalidWithdrawalException e)
{
System.out.println("your balance is low");
}
}
public void customerDeposit()
{
try
{
newb = deposit + balance;
System.out.println("new balance: " + newb);
}
catch (IllegalArgumentException e)
{
e.printStackTrace();
}
}
}
public class AccountManager
{
public static void main(String[] args)
{
//Scanner scan = new Scanner( System.in );
AccountServer w = new AccountServer();
AccountServer d = new AccountServer();
w.withDrawal(200.00, 100.00);
d.transaction(-200.00, -100.00, 300.00);
//transaction(deposit);
}
}
any help?