Archive for May 7th, 2013

Java Program 7 – User Defined Exception

Program

class DiscountException extends Exception {

/*    public String getMessage() {
    
        return "Invalid Discount Rate";
    }
*/
    public String toString() {
    
        return "Invalid Discount Rate";
    }
}

class jijo {
/*    
    public String getMessage() {
    
        return "Jijo Object 2";
    }
*/
    public String toString() {
    
        return "Jijo Object 1";
    }

}

class DiscountCalculator {

    public double calculate(double amt, double rate) throws DiscountException {
    
        if (rate>10) {
            throw new DiscountException();
        }
        return amt*rate/100;
    }
}

Read more »

Last updated by at .