For this program you will build a 'coin bank' simulator. When the program opens, the screen is empty. The load bank action will do one of the following: a) read a bank.txt file to load the quarters, dimes, nickels, and pennies for the start of the bank (this is the full credit option) or b) take user inputs from the in bank fields for quarters, dimes, nickels and pennies (reduced credit option). See the discussion below for details on these alternatives. After coin counts are determined, the Load Bank process finishes by instantiating a Bank.java object by sending it the entered starting values (to the constructor of the Bank.java class). The initial screen: see image.
After instantiation, the bank class returns the total value in the bank: see image.
Note that on the form, the 'in bank' fields have now been disabled as has the Load Bank command button, but the +/- buttons have been enabled.
The form must verify that the 'in bank' values are integers, so that they can be sent to the Bank.java class for instantiation. No other data validation is done in the form.
Following instantiation, the user will use the plus/minus buttons to add or remove single coins of each type to/from the bank, with each change resulting in a revised Total Value entry. Behind the form, these plus/minus actions are calling methods of the Bank.java class which adjust the internal values and return the revised bank total. Controls should be in place in the bank.java class to prevent the coin counts from going negative.
The clear button resets the screen to original status (all text fields active and cleared) and allows the user to re-load (or re-enter) coin counts and re-instantiate a bank class object
For full credit, the 'load bank' action on the form should use a JFileChooser to let the user select a Bank.txt file from which to load the starting values. A sample bank.txt file has been included with the project. The bank.txt file contains one value per line, with the first line containing the number of quarters in the bank, second line the number of dimes, third the number of nickels, and fourth the number of pennies. Please note that the selection and reading of the bank.txt file is to be done by the form. In the TriviaQuiz program that job was done inside the business object, but that is not the case here. The form program reads the bank.txt file to fill the display fields, and then instantiates the Bank.java object by sending the values to the constructor of that class.
Alternative: if you are unable to get your program to select and read the text file, then you should write the Load Bank event so that it accepts user input from the coin count fields. The program would then proceed as normal by sending those values - as integers to the Bank.java constructor.
At a minimum the Bank.java class should have:
To clarify on item 3, you have a choice: create separate methods to add and remove one unit of each type of coin from the bank, or create a 'general process' method that can add or remove coins of any type. In other words, you could have a method that just adds one quarter and another method that adds one dime, and another that removes one quarter, etc. or you could have a single method that is told which coin type to add/subtract 1. The form is the view into the instantiated bank class. It instantiates the bank class after a load action and manages all communication to/from the bank.java class.
Obviously, the total value of the bank is a simple calculation using the cash value of each coin type: .25 for quarters, .10 for dimes, .05 for nickels, and .01 for pennies. This is displayed with currency formatting in the Total Value text area.