You are required to build an application for charity organization. Your application will keep track of the items given out as charity. The items are donated by people and your application will keep track of each donation in persistence store. CharityItem: description (String), quantity (int), estimatedAmount (double), donor name (String), Donor contact (String) You are also required to do some exception programming/handling. If a charity with a value greater than 2 lacs is donated, then you will raise the ShowOffCharityException. You will have to create an exception class for this and the exception will be raised from the constructor of the CharityItem class under the said condition. You will also write code at other places wherever required to deal with this exception. Please note that you will make your ShowOffCharityException as a checked exception.
class ShowOffCharityException extends Exception {
public ShowOffCharityException(String message) {
super(message);
}
}
class CharityItem {
private String description;
private int quantity;
private double estimatedAmount;
private String donorName;
private String donorContact;
public CharityItem(String description, int quantity, double estimatedAmount, String donorName,
String donorContact) throws ShowOffCharityException {
if(quantity>=2) {
throw new ShowOffCharityException("A charity with a value greater than 2 lacs is donated");
}
this.description = description;
this.quantity = quantity;
this.estimatedAmount = estimatedAmount;
this.donorName = donorName;
this.donorContact = donorContact;
}
}
class App {
public static void main(String[] args) {
}
}
Comments
Leave a comment