Question: NegativeException class Custom Exception Specification: Create a BankAccount class that can be used to maintain a bank account balance. Its constructors, setter, and methods should
NegativeException class Custom Exception Specification: Create a BankAccount class that can be used to maintain a bank account balance. Its constructors, setter, and methods should throw a NegativeException if there is an attempt to take the balance below zero or if there is an attempt to deposit or withdraw a negative amount. Design a NegativeException class to extend the Exception class to include additional functionality of a new message detailing the error being sent when the exception is thrown. Use the main class to test the exception-handling (try-catch) techniques. The following errors will throw NegativeException A negative starting balance is passed to the constructor A negative amount is passed to the deposit method A negative amount is passed to the withdrawal method The amount passed to the withdraw method is greater than the balance Class Design: You may add any additional variables and methods to implement the logic of your solution. Class Name: NegativeException Private data fields (properties): none Inheritance: Exception class Public methods: none Constructors: Constructors Parameter list and purpose NegativeException (String errMessage)->parameter list Call super(errMessage) NegativeException (double amt)->parameter list Call super("Starting balance cannot be negative:" + amt) Class Name: BankAccount Private data fields (properties): balance: double Constructors: Constructor Parameter list and purpose BankAccount ()->parameter list Set balance to 0.0 BankAccount (double bal)->parameter list--throws NegativeException Set balance to bal. If bal is negative, throw new NegativeException Public methods: Method name Return type Parameter list and purpose getBalance double ()->parameter list Return current balance setBalance void (double bal)->parameter list--throws NegativeException Set balance to bal. If bal is negative, throws new NegativeException deposit void (double dep)->parameter list - throws NegativeException COSC 1437 Java Assignment 6 DataOperations.docx Add deposit to balance. If deposit is negative, throws new NegativeException withdrawal void (double withd)->parameter list--throws NegativeException Subtract withdrawal from balance. If withdrawal is negative or withdrawal amount is greater than balance, throws new NegativeException with different error message Assignment Instructions: 1. Create a NetBeans project and named it FirstName_LastName_A6 2. Create a separate java file for each class: NegativeExceptin.java and BankAccount.java 3. In your main class, create BankAccount instance and test each error to make sure NegativeException is called. See program output. 4. Name your variables clearly 5. Add comments to document your project and code 6. Add space/indentation to make your code easier to read 7. Zip your assignment and submit it in Canvas for grading NegativeException class Custom Exception Specification: Create a BankAccount class that can be used to maintain a bank account balance. Its constructors, setter, and methods should throw a NegativeException if there is an attempt to take the balance below zero or if there is an attempt to deposit or withdraw a negative amount. Design a NegativeException class to extend the Exception class to include additional functionality of a new message detailing the error being sent when the exception is thrown. Use the main class to test the exception-handling (try-catch) techniques. The following errors will throw NegativeException A negative starting balance is passed to the constructor A negative amount is passed to the deposit method A negative amount is passed to the withdrawal method The amount passed to the withdraw method is greater than the balance Class Design: You may add any additional variables and methods to implement the logic of your solution. Class Name: NegativeException Private data fields (properties): none Inheritance: Exception class Public methods: none Constructors: Constructors Parameter list and purpose NegativeException (String errMessage)->parameter list Call super(errMessage) NegativeException (double amt)->parameter list Call super("Starting balance cannot be negative:" + amt) Class Name: BankAccount Private data fields (properties): balance: double Constructors: Constructor Parameter list and purpose BankAccount ()->parameter list Set balance to 0.0 BankAccount (double bal)->parameter list--throws NegativeException Set balance to bal. If bal is negative, throw new NegativeException Public methods: Method name Return type Parameter list and purpose getBalance double ()->parameter list Return current balance setBalance void (double bal)->parameter list--throws NegativeException Set balance to bal. If bal is negative, throws new NegativeException deposit void (double dep)->parameter list - throws NegativeException COSC 1437 Java Assignment 6 DataOperations.docx Add deposit to balance. If deposit is negative, throws new NegativeException withdrawal void (double withd)->parameter list--throws NegativeException Subtract withdrawal from balance. If withdrawal is negative or withdrawal amount is greater than balance, throws new NegativeException with different error message Assignment Instructions: 1. Create a NetBeans project and named it FirstName_LastName_A6 2. Create a separate java file for each class: NegativeExceptin.java and BankAccount.java 3. In your main class, create BankAccount instance and test each error to make sure NegativeException is called. See program output. 4. Name your variables clearly 5. Add comments to document your project and code 6. Add space/indentation to make your code easier to read 7. Zip your assignment and submit it in Canvas for grading
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
