Java Swing代写:CIS304 Bank Account Application

Introduction

用Java Swing作为GUI,从文件中读取信息并显示,实现逻辑,整体控件不多,很基础的作业。

What to turn in

Use Export Project in NetBeans to export your project to a zip file, name it YourLastName_FirstName_project.zip. Send the file as a single attachment through Blackboard. The subject of this email is YourLastName_FirstName_project.

Note

  • Write your name as a comment line at the very beginning of each .java program: 1 point deducted for each file without your name at top.
  • Besides this documentation, I also provide you a text file, accounts.txt (described below). You should download this text file into the directory of your Netbeans project for your programs. Make sure when accessing this text file programmatically, your program just uses the file name without explicitly providing a path (so called relative path). For instance,
1
File accountFile = new File("accounts.txt");

For more information about the absolute path, refer to chapter 18 lecture slides. Failing to use the relative path loses 4 points.

Suggestions

  1. Start early and start from simple – this is VERY important. For example, begin from the week when the project is available. As the first step, you construct the GUI but not implement functions for button clicks.
  2. For the give function buttons, you may start to implement the Exit function first, and then the functions of Deposit and Withdraw buttons.
  3. Always keep a copy of your working code before you implement more requirements.

Requirements in summary

1) Develop a Java GUI application that reads account information from the provided text file (accounts.txt), shows all account numbers in a JComboBox, and displays other GUI controls as shown in Fig. 1;
2) Exit button : Quit the application;
3) Deposit button: Make a deposit to a selected account;
4) Withdraw button: Make a withdrawal from a selected account;
5) Transfer To button: Make a transfer from a selected account to a beneficiary account;

Requirements in details

GUI in general

Once the program starts, it reads all account information from accounts.txt (each row in the file is a account record and is in the format of

accountNumber<>openDate<>customerName<>balance

The openDate is in the format of year/month/day.) It then fills a JComboBox with all account numbers and shows other GUI controls as in Fig. 1. Your program must be able to “read” the file of this format programmatically because when I test your project, the file content (not the format) will be changed.
When you select an item (account number) from the JComboBox, the corresponding values for openDate, customerName, and balance will be shown in the three read-only text fields, and the Deposit, Withdraw, and Transfer To buttons become enabled, see Fig. 2.

Exit

  • Clicking this button to close the frame and exit the program.
  • Instead of using mouse to click the button, pressing Alt + x will also trigger the Exit button.

Deposit

  • (After selecting an account number from the JComboBox), clicking the Deposit button will popup a window as shown in Fig. 3 asking you to enter a deposit amount for the selected account. Hint: this dialog window is generated by JOptionPane.showInputDialog().
  • If you enter a non-negative number, such as 100, the amount will be deposited to the account. See Fig 4 - the balanced is adjusted accordingly. The accounts.txt file should also be updated accordingly as well.
  • If you clicking Cancel in Fig. 3, nothing will happen to this account.
  • If an invalid deposit amount is entered in Fig. 3, such as -100 or $100, you will see an error message as shown in Fig 5.

Hint: this dialog window is generated by JOptionPane. showConfirmDialog().

Withdraw

  • (After selecting an account from the JComboBox), clicking the Withdraw button will popup a window as shown in Fig. 6 asking you to enter a withdrawal amount for the selected account.
  • If you enter a non-negative number, such as 100, and if the account balance is sufficient, the withdrawal will be made from the account successfully. See Fig. 7, the balanced is adjusted. The accounts.txt file should also be updated accordingly as well.
  • If you clicking Cancel in Fig. 6, nothing will occur to this account.
  • If an invalid withdrawal amount is entered in Fig. 6, such as -100 or $100, you will see an error message as shown in Fig 8.
  • If a withdrawal amount is greater than the balance, you show an error message and stop the withdrawal.

Transfer To

  • (After selecting an account from the JComboBox), clicking the Transfer To button will popup a window as shown in Fig. 10 asking you to enter a beneficiary account number.
  • If a valid account number (any number existing in the JComboBox) is entered, after click OK button, a window like Fig. 11 pops up asking for amount to transfer.
  • If a valid amount is entered, and the balance is not less than this amount and sometimes the sum of this transfer amount and a transfer fee, the transfer will be succeeded as shown in Fig. 12 and 13. The transfer fee is only applied to account with the balance less than $10000 which is specified in AccountConstants interface (more about AccountConstants see end of this document).
  • If an invalid beneficiary account number (i.e., a number which does not exist in the account number JComboBox) is entered in Fig. 10, Fig. 14 shows the error message.
  • If the balance is not sufficient for the transfer amount, Fig. 15 shows the error message.
  • If the balance is not sufficient to cover both transfer amount and transfer fee (when such a fee applies), Fig. 16 shows the error message.

Design requirements

You must have the following five classes (at least 5 points deduction for missing a required class).

  • AccountConstants – contains two constants, CHECKING_BALANCE_THRESHOLD (value is 10000) and TRANSFER_FEE (value is 2.0). For this project, the business rule is as follows:
    • When making a transfer to a beneficiary account, if the balance of the transferring account is less than CHECKING_BALANCE_THRESHOLD, TRANSFER_FEE is deducted from the balance after the transfer is made. If the balance is not sufficient to cover both CHECKING_BALANCE_THRESHOLD and TRANSFER_FEE (if the fee applies), the transfer should not be made. If the balance of transferring account is not less than CHECKING_BALANCE_THRESHOLD, TRANSFER_FEE is waived for this transfer.
  • Account – transferTo() method is abstract. deposit() and withdraw() are not abstract. If you need, feel free to define other methods, such as getBalance(), in the Account class.
  • CheckingAccount: extends Account and implements the transferTo method (refer to the above diagram). The returned value of transferTo method is defined as follows.
    • return 0: transfer successful and without transfer fee
    • return 1: transfer successful and with the transfer fee applied
    • return -1: transfer unsuccessful because balance is less than transfer amount and transfer fee
    • return -2: transfer unsuccessful because balance is less than transfer amount
  • AccountUtility – reads accounts.txt file, updates the file, and provides data for other programs.
  • AccountApp – is the only Java program having the main method. This must be the only file with a main method. If not, you lose 5 points.
    Depending on your design and it’s your decision that you may have more Java programs than those specified above.