The program below is the answer to Deitel’s Java How to Program (9th Edition) Chapter 3 Exercise 3.12.

Question: Modify class Account (Fig. 3.13) to provide a method called debit that withdraws money from an Account. Ensure that the debit amount does not exceed the Account’s balance. If it does, the balance should be left unchanged and the method should print a message indicating “Debit amount exceeded account balance.” Modify class AccountTest (Fig. 3.14) to test method debit.

To run the application save both files with the same name as the class (because it is a public class) and with the .java file extension (in this case Ex03_12.java and Ex03_12_Test.java). Then compile both classes and run Ex03_12_Test. Ex03_12 will not run because it does not have a main method.

To compile both classes at the same time using the command prompt, use the command

javac Ex03_12.java Ex03_12_Test.java

To run Ex03_12_Test, use the command

java Ex03_12_Test

Below is Class Ex03_12_Test.java to test Class Ex03_12.java

Click here to see other answers to Java How to Program.

Write A Comment