Answer to Question #296559 in Java | JSP | JSF for bfhskd

Question #296559

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. 


1
Expert's answer
2022-02-11T13:40:11-0500


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) {




	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS