1

Program to raise an exception stating "Further Transactions Not Possible until clearance of bill." when a customer's unpaid credit card amount cross $2000 or is unpaid upto 45 days. Assume that the current date is 01/12/2015.

  1. Create a custom exception class OverLimitException which extends Exception.
  2. Add a constructor which takes a Throwable object, calls the super class constructor using super() and prints the output as described in the problem statement.

I created two classes one main and the other account

Account.java

import java.text.*;
import java.util.*;
import java.util.concurrent.TimeUnit;

public class Account {

String accountNumber;
String accountName;
Double dueAmount;

public Account(String accountNumber, String accountName,Double dueAmount) throws ParseException {
    this.accountNumber = accountNumber;
    this.accountName = accountName;
    this.dueAmount = dueAmount;
}

public Account() {
}

public Boolean validate(String dueDate,Double unpaid,Double amount){
    DateFormat sf = new SimpleDateFormat("dd/MM/yyyy");
    sf.setLenient(false);
    try{
        Date d = sf.parse(dueDate);
        Date d1 = sf.parse("01/12/2015");
       // long curDate = new Date().getTime();
        long diff =d1.getTime() - d.getTime();
        long daysDiff = TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
        if(daysDiff > 45 || unpaid > 2000){
            throw new OverLimitException("Further Transactions Not Possible until clearance of bill.");
        }
    }catch(Exception e){
        return false;
    }
    return true;
}

public void display() {       
    System.out.println("Transaction successsfully completed.");
    System.out.println("Account Number : "+this.accountNumber);
    System.out.println("Account Name : "+this.accountName);
    System.out.println("Unpaid Amount : "+this.dueAmount);
}
}

But am getting an error stating

 error: cannot find symbol
 throw new OverLimitException("Further Transactions Not Possible until clearance of bill.");
 ^
 symbol: class OverLimitException

Can any one please help me solve this problem?

1
  • And hint: you don't want to return Boolean, but boolean. Commented Aug 26, 2016 at 14:21

2 Answers 2

3

OverLimitException is not an exception that comes with Java.

Like the other classes you created, you have to write that class, too; like:

public class OverLimitException extends RuntimeException {

and provide a constructor that takes a message string for example.

Sign up to request clarification or add additional context in comments.

Comments

1

The valiade function has to throw OverLimitException and you have to define it

public Boolean validate(String dueDate,Double unpaid,Double amount) 
      throws OverLimitException{
      ...
      if(daysDiff > 45 || unpaid > 2000){
          throw new OverLimitException("Further Transactions Not Possible  until clearance of bill.");
    }
    ...

}

and implement the OverLimitException ; here is an example

     public class OverLimitException extends Exception {
         public OverLimitException(String message) {
            super(message);
         }
     }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.