Question

IN JAVA Problem 1 Write a custom exception class named ‘AccountNotFoundException’ that extends Exception and uses...

IN JAVA

Problem 1

Write a custom exception class named ‘AccountNotFoundException’ that extends Exception and uses invokes the parent’s constructor passing the message “Account “ + accountNumber “ + “ does not exist!”.

Problem 2

Write a method called ‘verifyAccountStatus’ that takes the account number as a formal parameter. Assume there is logic in the method to call off to a database to determine if the account exists. Such a call may look like:

boolean accountExists = CHECKINGACCOUNTDAO.verifyAccountExists(accountNumber);

If the account does not exist, throw the custom exception written above and declare the method throws this exception in the method signature.

Problem 3

After declaring that the method throws the ‘AccountNotFoundException’, what happens? Would it make more sense to handle this exception in the veriftyAccountStatus method or have the caller deal with the exception?


Homework Answers

Answer #1


Answer 1)
====

public class AccountNotFoundException extends Exception {
   public AccountNotFoundException(int accountNumber ) {
       super("Account " + accountNumber + " does not exist!");
   }
}

Answer 2)
=====
public boolean verifyAccountStatus(int accountNumber) throws AccountNotFoundException {
       boolean accountExists = CHECKINGACCOUNTDAO.verifyAccountExists(accountNumber);
       if(!accountExists)
           throw new AccountNotFoundException(accountNumber);
       return accountExists;
   }
  
  
Answer 3)
=====
The exception should be handled by the caller and not the verifyAccountStatus() because the signature says it will throw the exception.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
C# Step 1: Create a Windows Forms Application. Step 2: Create a BankAccount class. Include: Private...
C# Step 1: Create a Windows Forms Application. Step 2: Create a BankAccount class. Include: Private data fields to store the account holder's name and the account balance A constructor with 0 arguments A constructor with 1 argument (account holder's name) A constructor with 2 arguments(account holder's name and account balance) Public properties for the account holder's name and the account balance. Do not use auto-implemented properties. A method to increase the balance (deposit) A method to decrease the balance...
In java just need work in the billards class it is in bold everything else is...
In java just need work in the billards class it is in bold everything else is done just the sections marked TODO Suppose that you have several numbered billiard balls on a pool table. The smallest possible number on the ball is “1”. At each step, you remove a billiard ball from the table. If the ball removed is numbered n, you replace it with n balls randomly numbered less than n. For example, if you remove the “5” ball,...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { flavor = s; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         System.out.println(pepper.getFlavor());     } } a. a class variable b. a constructor c. a local object variable d....
Write a class called Item that has a string field called name and a double field...
Write a class called Item that has a string field called name and a double field called price and an integer field called quantity. In main, create a bag of type Item and place several item objects in the bag. Then in main calculate the total price of items purchased. You may remove each item and add the price to a total variable in a loop. The loop should end when the bag is empty. Using bag algorithms public final...
Do the TODOs in SongFileAccessor.java. It inherits from FileAccessor class. TODO 1: Implement the processLine method....
Do the TODOs in SongFileAccessor.java. It inherits from FileAccessor class. TODO 1: Implement the processLine method. When the text file is processed, each line of text will be passed to processLine . Each line contains 4 fields: title, album, artist, and play time. The album field is optional. Each field is separated by a comma. TODO 2: Implement the songToCSVString method. This method takes a Song object as a parameter and returns a String which is the csv representation of...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT