Home

 

Creating a Java class using the New Java Class wizard

To create a Java class using the New Java Class wizard:

Select the itso.rad75.bank.model package and click the Add Java Class icon in the action box.

In the New Java Class dialog, enter the following data and click Finish.

Package: itso.rad75.bank.model (click Browse to select the package)
Name: Transaction
Modifiers: Select public (default) and abstract.
Superclass: java.lang.Object (default). You can change the superclass by clicking Browse in the Superclass Selection dialog (Figure | 18), in the Choose a type field type the name of the superclass and click OK. All matching types are listed while writing.

Figure 8-18 Superclass Selection dialog

Interfaces: java.io.Serializable, click Add and type the interface name in the Choose interfaces field. All matching types are listed. Select the required interface and click Add. If you have added all required interfaces, click OK to leave the dialog (Figure | 19).

Figure 8-19 Implemented Interfaces Selection dialog

Which method stubs would you like to create:
public static void main(String[] args): clear (default)-Adds an empty main method to the class and makes the class an executable one. In the example, only the class BankClient must be executable.
Constructors from superclass: clear (default)-Copies the constructors from the superclass to the new class.
Inherited abstract methods: clear-Adds to the new class stubs of any abstract methods from superclasses or methods of interfaces that have to be implemented. In the example, it is useful for the classes ITSOBank, Credit, and Debit.
Generate comments: clear (default)
Click Finish to create the Java class (Figure | 20). Notice that a line appears between the package and the Bank interface.

Figure 8-20 New Java Class dialog

Note: You can add a class to the class diagram using drag and drop, or select Visualize Æ Add to Current Diagram.

ITSOBank example-Classes

Repeat the foregoing steps to create the following Java classes, which are described in Interfaces and classes structure:

Transaction class into package itso.rad75.bank.model

Customer class into package itso.rad75.bank.model

Account class into package itso.rad75.bank.model

ITSOBank into package itso.rad75.bank.impl

ITSOBankException into package itso.rad75.bank.exception

InvalidCustomerException into package itso.rad75.bank.exception

InvalidAccountException into package itso.rad75.bank.exception

InvalidTransactionException into package itso.rad75.bank.exception
ibm.com/redbooks