CIS 304 Project
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. (3 points)
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, 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 (20 points); 2) Exit button : Quit the application(1 point); 3) Deposit button: Make a deposit to a selected account (12 points); 4) Withdraw button: Make a withdrawal from a selected account (12 points); 5) Transfer To button: Make a transfer from a selected account to a beneficiary account (15 points). Fig. 1 When the Java program starts
Requirements in details:
• GUI in general (20 points) 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, 2 where <> is the partition/delimiter between two fields. 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. Fig. 2 The GUI after selecting an account number from the JComboBox
• Exit (1 point) • 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 (12 points) • (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(). Fig. 3 Make a deposit • 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. Fig. 4 Balance is updated after a successful deposit 3 • 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(). Fig. 5 A popup window notifies user that a deposit amount is invalid.
• Withdraw (12 points) • (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. Fig. 6 Withdraw money • 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. Fig. 7 Balance is updated after a successful withdrawal • 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. Fig. 8 A popup window notifies user that a withdrawal amount is invalid. • If a withdrawal amount is greater than the balance, you show an error message and stop the withdrawal. 4
• Transfer To (15 points) • (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. Fig. 10 Transfer money to a beneficiary account • 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. Fig. 11 Enter a transfer amount • 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). Fig. 12 A pop window notifies user about the successful transfer. Fig. 13 After the successful transfer, balance is updated. 5 • 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. Fig. 14 Invalid beneficiary account is entered • If the balance is not sufficient for the transfer amount, Fig. 15 shows the error message. Fig. 15 Error message when the balance is less than transfer amount • 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. Fig. 16 Error message when the balance is less than the sum of transfer amount and transfer fee Requirements for the program design is specified in the next page. 6
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.
Account(String, String, GregorianCalendar, double)
deposit (double): boolean
withdraw (double): boolean
transferTo(Account, double): int
-number: String
-name: String
-openDate:GregorianCalendar
-balance: double
Account
CheckingAccount(String, String, GregorianCalendar, double)
transferTo(Account, double): int
CheckingAccount • 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.