EJB Deployment   «Prev  Next»

Write Customer client[EJB] - Exercise

Course Project Part 1B: Write the Customer client


Objective: Write a Customer program that is a client to a BankAccount bean.

Exercise scoring

This exercise is worth a total of 5 points. To receive full credit, you'll need to write a client program and send the code to a tutor for scoring.

Background/overview

You will use the same BankAccount bean and download files as you did in part A of this exercise. To recap, I have provided a very simple BankAccount bean. The home interface contains the following create() methods:
BankAccount create() 
BankAccount create(String accountName) 

The bean's methods are as follows:
double getBalance() 
void credit(double amount) 
void debit(double amount) throws NSFException
String getInfo() 

Your job is to write the client program. Some words of explanation are in order:
  1. BankAccount is a very simple class. It remembers the current balance and the name of the customer. The balance starts as 0.0.
  2. It is created with either no name or an account name. If no name is provided, the account name will be named anonymous.
  3. getBalance() returns the current balance.
  4. credit() adds the amount to the balance.
  5. debit() subtracts the amount from the balance. If the balance would become negative by debiting the amount, it throws a NSFException (Non-Sufficient Funds) and leaves the balance as it was.
  6. getInfo() returns a string that contains the account name and the balance.

Download files


Use the same download files as you did in Part 1A of this exercise. They were:
  1. BankAccount.class
  2. BankAccountHome.class
  3. BankCustomer.skel
  4. runClient.bat
  5. BankAccountBean.class
  6. BankAppClient.jar
  7. NSFException.class
  8. BankAccountEJB.jar
  9. BankCustomer.class
  10. compileClient.bat

Instructions

Make sure the BankAccount bean is deployed. If it is not, repeat the steps in the previous exercise. Using the file BankCustomer.skel as a skeleton, write the BankCustomer.java client so that it performs the following:
a. Create a bank account bean with your name (minnie is used in the provided BankCustomer.class).
b. Credit your balance with $100.
c. Get the balance and display it on System.out.
d. Debit your balance with $75.
e. Get the balance and display it on System.out.
f. Debit your balance with $50.
g. Catch the NSFException that is thrown.
h. Display the exception and the balance on System.out.
Edit the compileClient.bat to reflect the local environment. Compile the BankCustomer program and run it after editing the runClient script file to reflect your local system. It will access the BankAccount bean and then display the results on standard out.

Hints


If you have any problems with any part of this exercise, search the website for more information.
If BankCustomer.java won't compile, make sure you have edited the script files correctly to reflect your environment.
If the BankCustomer does not access the BankAccount bean when you execute it, make sure the BankAccount bean was successfully deployed on the J2EE platform by examining the window of the J2EE program. If nothing is shown there, make sure you started the program with the -verbose flag.
Run the provided BankCustomer.class file to verify that all is working (if you overwrote it when creating BankCustomer.java. Depending on where the problem is, re-deploy the bean or fix the problem in the client.
Use the HelloClient.java program used in Part 1A of this exercise for ideas. Make sure that you added the NSFException.class file to the jar file.

Submitting your exercise

When you have completed your exercise, paste the code for BankCustomer.java in the text box below and click the Submit button to continue on to the next lesson.