HELP WITH JAVA PROGRAMMING PROJECT! MUST HAVE BOTH GUIs! LOTS OF INSTRUCTIONS RE
ID: 3915613 • Letter: H
Question
HELP WITH JAVA PROGRAMMING PROJECT! MUST HAVE BOTH GUIs! LOTS OF INSTRUCTIONS
READ THE PROGRAM EXPECTATIONS FOR THE ARRAY or .TXT FILE!!!
READ THE PROJECT 2 DESCRIPTION FOR ALL THREE CLASSES!
This project involves writing a program that implements an ATM machine. The interface to the
program should be a Java GUI that looks similar to the above GUIs
The program should consist of three classes.
1. The first class should define the GUI. In addition to the main method and a constructor to
build the GUI, event handlers will be needed to handle each of the four buttons shown
above. When the Withdraw button is clicked, several checks must be made. The first
check is to ensure the value in the text field is numeric. Next a check must be made to
ensure the amount is in increments of $20. At that point an attempt to withdraw the funds
is made from the account selected by the radio buttons. The attempt might result in an
exception being thrown for insufficient funds, If any of those three errors occur a
JOptionPane window should be displayed explaining the error. Otherwise a window
should be displayed confirming that the withdrawal has succeeded. When the Deposit
button is clicked the only necessary check is to ensure that the amount input in the
textfield is numeric. Clicking the Transfer button signifies transferring funds to the
selected account from the other account. The checks needed are to confirm that the
amount supplied is numeric and that there are sufficient funds in the account from which
the funds are being transferred. Clicking the Balance button will cause a JOptionPane
window to be displayed showing the current balance in the selected account. The main
class must contain two Account objects, one for the checking account and another for the
savings account.
2. The second class is Account. It must have a constructor plus a method that corresponds
to each of the four buttons in the GUI. It must also incorporate logic to deduct a service
charge of $1.50 when more than four total withdrawals are made from either account.
Note that this means, for example, if two withdrawals are made from the checking and
two from the savings, any withdrawal from either account thereafter incurs the service
charge. The method that performs the withdrawals must throw an InsufficientFunds
exception whenever an attempt is made to withdraw more funds than are available in the
2
account. Note that when service charges apply, there must also be sufficient funds to pay
for that charge.
3. The third class is InsufficientFunds, which is a user defined checked exception.
The google recommended Java style guide, provided as link in the week 2 content, should be used to
format and document your code. Specifically, the following style guide attributes should be addressed:
? Header comments include filename, author, date and brief purpose of the program.
? In-line comments used to describe major functionality of the code.
? Meaningful variable names and prompts applied.
? Class names are written in UpperCamelCase.
? Variable names are written in lowerCamelCase.
? Constant names are in written in All Capitals.
? Braces use K&R style.
In addition the following design constraints should be followed:
? Declare all instance variables private
? Avoid the duplication of code
Test cases should be supplied in the form of table with columns indicating the input values, expected
output, actual output and if the test case passed or failed. This table should contain 4 columns with
appropriate labels and a row for each test case. Note that the actual output should be the actual results
you receive when running your program and applying the input for the test record. Be sure to select
enough different scenarios to completely test the program.
Note: All code should compile and run without issue.
Submission requirements
Deliverables include all Java files (.java) and a single word (or PDF) document. The Java files should be
named appropriately for your applications. The word (or PDF) document should include screen captures
showing the successful compiling and running of each of the test cases. Each screen capture should be
properly labeled clearly indicated what the screen capture represents. The test cases table should be
included in your word or PDF document and properly labeled as well.
Submit your files to the Project 2 assignment area no later than the due date listed in your LEO classroom.
You should include your name and P2 in your word (or PDF) file submitted (e.g.
firstnamelastnameP2.docx or firstnamelastnameP2.pdf)
Project 2 Expectations
Please review General Programming Expectations document located in Week 2 under Week 2 Checklist.
OBTAINING DATA FOR ASSIGNMENT 2
For Project 2, the assignment does not suggest a way of obtaining data for processing. There is a normal assumption that the programmer will generate several instances of the class and pass in a set of hard-coded values as arguments. There are two ways of obtaining the data for this program. The program can either (1) use a two-dimensional array with a set of initialized values or (2) a data file with the data being read into the program and then assigned into a two-dimensional array. Since there are various data types in the array row, you need to determine that best data type declaration for the array. Either way, a data file is supplied for this assignment to make it easier to test the programs among the members of this course and for the instructor to run the program for feedback and grading. The file to use with this program is PRJ2Accounts.txt; this file was created for this specific course. It is expected that you will use this file. The following is the data in the file that can also be used to initialize the two-dimensional array:
7623, S, Jones, Phyllis, 2000.00, 0
7623, C, Jones, Phyllis, 1200.00, 2
8729, S, Smith, Cletus, 1000.00, 1
8729, C, Smith, Cletus, 1700.00, 0
7321, S, Booth, Betty, 4500.00, 2
3242, C, Seybright, Sam, 4612.00, 0
3242, S, Seybright, Sam, 100.00, 3
9823, S, Blu, Oscar, 234.00, 2
9823, C, Blu, Oscar, 2345.00, 0
2341, S, Grief, Sally, 12373.12, 1
2341, C, Grief, Sally, 5421.12, 2
8321, S, Matchel, Jacques, 2314.00, 0
8321, C, Matchel, Jacques, 56233.00, 0
The fields/columns in the file are
1. Bank Account Number
2. Type of Account [S = Savings; C = Checking]
3. Last Name of Account Holder
4. First Name of Account Holder
5. Initial Balance in the Account
6. Current Number of Transactions
If you chose to use a file to input the data, an additional method can be added to the code as either part of Account Class or an independent method inserted before the main () method. Reading a file and assignment the data into an array was covered in the prior assignment.
SUGGESTED DESIGN FOR ASSIGNMENT 2
Here is one skeleton design of this program.
package cmis242.prj2smithx;
[imports here]
public class CMIS242 PRJ2SmithX {
public static Data Manipulation {
[Declare array]
[METHOD: Coding to read in file and assign to array]
[MEHTOD: update the various rows of the array]
[METHOD: Display the output]
} //end public static Data Manipulation
public static class ATM_GUI {
[Constructor (), define GUI Interface, listeners]
} // end public static class ATM_GUI
public static class Accounts {
[Balance, deposit, withdrawal, transfer]
} // end public static class Accounts
public static class Savings extends Accounts {
[Constructor (), insufficient funds, fee, transfer, etc.]
} // end public static class Savings extends Accounts
public static class Checking extends Accounts {
[Constructor (), insufficient funds, multiples, fee, transfer, etc.]]
} // end public static Checking extends Accounts
public static void main (String args[]) {
[Declare instance of class]
[Call to read and assign file]
[Call to display output before any transactions]
[Call class to perform transactions]
[Call to display output after transactions completed]
} // end public static void main (String args []) {
} // end public class CMIS242 PRJ2SmithX
The GUI Class
An example of what the ATM screen should look like the one displayed at the beginning of the assignment in Project 2.pdf. There are two issues with the window as it appears in the document. Because you have a set of accounts, there should be a TextField in the window to enter an account number. The current TextField shown should be considered the entry of the bank account number. Both TextFields should have a label explaining the purpose of the field. The bottom of the window should be like the following display:
Account Number: [TextField window]
Amount of Transaction: [TextField window]
There should be displays for all errors, the balance, and the various transactions. Each display should contain a reference to the account number and type. Use JOptionPane for all these display occurrences. A partial listing of displays using JOptionPane is listed below but may not be all the possibilities.
• Accounts 7623 over 4 transactions: $1.50 added to transaction
• Withdrawal from 7623 must be in $20.00 multiples
• Insufficient funds for withdrawal 7623 Checking; Balance $18.50
• Insufficient funds in 7623 Savings; Balance $0.98
• The balance for 7623 Savings is $2,000.00
• The balance for 7623 Savings after $60.00 withdrawal is $1,940.00
• The balance for 7623 Checking after $100.00 deposit is $1,300.00
• The balance for 7623 Checking after transfer of $100 to Savings is $1,200.00 and balance for 7623 Savings after transfer of $100.00 from Checking is $2,140.00
When the user wishes to end the program, there should be a button to Exit/End the program. Add an Exit/End buttom to the GUI window.
There are some considerations in designing the program:
1. When the GUI window first displays only the Balance button should be available for use. Only after an account number is entered and verified as existing should the Deposit, Withdrawal, and Transfer buttons be available for use.
2. If the account number does not exist, an error message should be displayed. In normal circumstance, the program would ask is a new account should be created. For this assignment this process will not be implemented.
3. The single TextField is ambiguous. It is assumed that it exists for the number used to change the balance of the various accounts, but then why is there a Balance button. With the set of data provided, there would need to be a way of obtaining an account number to retrieve a balance. Then another field for the transaction needed for the other buttons. The following is the preferred display of elements on the window/panel already reference above:
a. The TextField currently visible on the window/panel is used to retrieve the account number.
b. A second TextField should be created to accept a transaction amount.
4. To the left of the TextField(s) should be a label as suggested above.
5. There is the possibility of the account holder having only a savings or checking account, therefore when the Transfer function is invoked there could be a problem requiring much coding. For this assignment assume that there are two accounts – a savings and a checking – for a bank customer.
6. To use the checkbox for processing, check the appropriate type field related to the account. [The Savings radio button is the default button.]
7. The checking used for Withdrawal should also apply to Deposit.
8. For the Insufficient Funds check, assume there is at least one multiple of $20 in the checking account and more than $1.00 in the savings account. Only one multiple is necessary to determine sufficient funds.
9. When a value is placed in a TextField it is normally a String and needs to be parsed into an integer or double, therefore, the statement “ensure . . . the text field is numeric.” is confusing. The text field for the transaction amount needs to be a double, so it should be parsed into a double.
10. If the array is a String data type, then the account number can be checked without parsing.
11. How to proceed with the accumulation of four withdrawals to impose a fee is not clear. The suggested rules for this requirement of the assignment use the following conditions for coding:
a. Check the number of withdrawals between the two bank accounts.
b. Sum the numbers in column 5 of the array for the two rows that relate to the accounts of one bank customer.
c. If the total withdrawals are less than 4, then process the withdrawal and add one to the appropriate account in column 5.
d. If the total withdrawals are 4, then add one to the appropriate account in column 5 and deduct a $1.50 from the balance of the appropriate account after the transaction is completed.
e. To streamline the check of more than four withdrawals, change both numbers in column 5 to a 9 once four is reached and use the 9 for adding the $1.50 rather than add the two accounts. [This is optional.]
f. The program can have a process that resets the number of withdrawals for each account to zero. [This is optional.]
EXPECTATIONS WHEN THE PROGRAM RUNS:
1. When the program begins the process of modifying the accounts, display in the Output Window of the IDE all the records in the array in horizontal order.
7623, S, Jones, Phyllis, 2000.00, 0
7623, C, Jones, Phyllis, 1200.00, 2
8729, S, Smith, Cletus, 1000.00, 1
8729, C, Smith, Cletus, 1700.00, 0
7321, S, Booth, Betty, 4500.00, 2
3242, C, Seybright, Sam, 4612.00, 0
3242, S, Seybright, Sam, 100.00, 3
9823, S, Blu, Oscar, 234.00, 2
9823, C, Blu, Oscar, 2345.00, 0
2341, S, Grief, Sally, 12373.12, 1
2341, C, Grief, Sally, 5421.12, 2
8321, S, Matchel, Jacques, 2314.00, 0
8321, C, Matchel, Jacques, 56233.00, 0
2. Follow the Test Plan scenarios presented in the matrix to process through the program.
3. When the user clicks the Exit/End button on the window, a new set of records is displayed in the Output Window of the IDE based on the values currently in the array. [All the changes made during the processing of data through the program run should be reflected in the new display.]
Change the Balance Enter Account # (four digits) 6323 Request Balance Current Balance 20000 Transaction Amount 150 Increase Decrease The new Balance for Account 6323 is 24400Explanation / Answer
import javax.swing.JOptionPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JScrollPane;
import java.awt.Dimension;
import java.awt.Color;
import java.awt.Font;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.FileReader;
public class ATM {
// these must be declared here to be seen in the Action classes
JFrame welcomeFrame;
JFrame mainFrame;
JFrame inputFrame;
JTextField numberField;
JTextField pinField;
JLabel verifyLabel;
JLabel outLabel;
JButton depositButton;
JButton withdrawButton;
JButton makeDepositButton;
JButton makeWithdrawalButton;
BankAccount theAccount;
NumberFormat currency;
double theAmount;
int width;
int height;
ArrayList accounts;
public ATM() {
int xLocation = 200;
int yLocation = 200;
// define frames
mainFrame = new JFrame("ATM");
welcomeFrame = new JFrame("Welcome to the ATM");
inputFrame = new JFrame("Enter Amount");
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
welcomeFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
inputFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
welcomeFrame.setLocation(xLocation,yLocation);
mainFrame.setLocation(xLocation,yLocation);
inputFrame.setLocation(xLocation,yLocation);
JPanel welcomePanel = new JPanel();
welcomePanel.setLayout(new FlowLayout(FlowLayout.CENTER,200,20));
welcomePanel.setPreferredSize(new Dimension(400,200));
JLabel pinLabel = new JLabel("Enter pin and Press Enter");
pinField = new JTextField(10);
pinField.addActionListener(new PinFieldAction());
welcomePanel.add(pinLabel);
welcomePanel.add(pinField);
JButton nextButton = new JButton("Next");
nextButton.addActionListener(new NextButtonAction());
//welcomePanel.add(nextButton);
// the main frame panel
JPanel thePanel = new JPanel();
width = 500;
height = 400;
thePanel.setPreferredSize(new Dimension(width,height));
thePanel.setBackground(Color.LIGHT_GRAY);
thePanel.setLayout(new FlowLayout(FlowLayout.CENTER,500,20));
JPanel inputPanel = new JPanel();
JLabel numberLabel = new JLabel("Type Amount and Press Enter");
numberField = new JTextField(10);
numberField.addActionListener(new NumberFieldAction());
inputPanel.add(numberLabel);
inputPanel.add(numberField);
JPanel verifyPanel = new JPanel();
verifyLabel = new JLabel("No Amount Entered");
verifyPanel.add(verifyLabel);
JPanel choosePanel = new JPanel();
JLabel chooseLabel = new JLabel("Choose Transaction");
choosePanel.add(chooseLabel);
JPanel buttonPanel = new JPanel();
JPanel makeButtonPanel = new JPanel();
JButton balanceButton = new JButton("Balance");
balanceButton.addActionListener(new BalanceButtonAction());
buttonPanel.add(balanceButton);
depositButton = new JButton("Deposit");
depositButton.addActionListener(new DepositButtonAction());
buttonPanel.add(depositButton);
withdrawButton = new JButton("Withdraw");
withdrawButton.addActionListener(new WithdrawButtonAction());
buttonPanel.add(withdrawButton);
makeDepositButton = new JButton("Make Deposit");
makeDepositButton.addActionListener(new MakeDepositButtonAction());
makeButtonPanel.add(makeDepositButton);
makeWithdrawalButton = new JButton("Make Withdrawal");
makeWithdrawalButton.addActionListener(new MakeWithdrawalButtonAction());
makeButtonPanel.add(makeWithdrawalButton);
JPanel finishButtonPanel = new JPanel();
JButton finishButton = new JButton("Finish");
finishButton.addActionListener(new FinishButtonAction());
finishButtonPanel.add(finishButton);
JPanel outPanel = new JPanel();
outPanel.setBackground(Color.LIGHT_GRAY);
outLabel = new JLabel("");
outLabel.setForeground(Color.RED);
outLabel.setFont(new Font("Courier",Font.BOLD,20));
outPanel.add(outLabel);
thePanel.add(choosePanel);
thePanel.add(verifyPanel);
thePanel.add(buttonPanel);
thePanel.add(makeButtonPanel);
thePanel.add(finishButtonPanel);
thePanel.add(outPanel);
welcomeFrame.getContentPane().add(welcomePanel);
welcomeFrame.pack();
welcomeFrame.setVisible(true);
mainFrame.getContentPane().add(thePanel);
mainFrame.pack();
inputFrame.getContentPane().add(inputPanel);
inputFrame.pack();
currency = NumberFormat.getCurrencyInstance();
// Initialize the database
// Load the data base
accounts = getAccountDataFromFile("accounts.data");
} // end constructor
ArrayList getAccountDataFromFile(String fileName) {
try{
ArrayList accounts = new ArrayList();
// add code here to read lines from the file
// (each line contains an initial balance)
// and add BankAccount objects to the ArrayList
return accounts;
} catch(Exception e) {
JOptionPane.showMessageDialog(null,"File Error. Program Aborted");
System.exit(0);
return accounts;
} // end try/catch
} // end getAccountDataFromFile
class PinFieldAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
// Get the pin number, verify that it is legal
// and then get the account from the ArrayList accounts
// and remove the following statement
theAccount = new BankAccount(1000000);
welcomeFrame.setVisible(false);
mainFrame.setVisible(true);
pinField.setText("");
} // end actionPerformed
} // end PinFieldAction
class NumberFieldAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
String input = numberField.getText();
if( ! isInputOK(input) ) {
JOptionPane.showMessageDialog(null,"Invalid input. Try again.");
numberField.requestFocus();
return;
} // end if
theAmount = Double.parseDouble(input);
welcomeFrame.setVisible(false);
inputFrame.setVisible(false);
mainFrame.setVisible(true);
verifyLabel.setText("Amount Entered was " + currency.format(theAmount));
} // end actionPerformed
} // end NumberButtonAction
class BalanceButtonAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
numberField.requestFocus();
drawBalance(outLabel,theAccount);
} // end actionPerformed
} // end BalanceButtonAction
class DepositButtonAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
inputFrame.setVisible(true);
numberField.setText("");
numberField.requestFocus();
withdrawButton.setEnabled(false);
makeWithdrawalButton.setEnabled(false);
} // end actionPerformed
} // end DepositButtonAction
class WithdrawButtonAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
inputFrame.setVisible(true);
numberField.setText("");
numberField.requestFocus();
depositButton.setEnabled(false);
makeDepositButton.setEnabled(false);
} // end actionPerformed
} // end WithdrawButtonAction
class MakeDepositButtonAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
// add code here to make the deposit
withdrawButton.setEnabled(true);
makeWithdrawalButton.setEnabled(true);
} // end actionPerformed
} // end MakeDepositButtonAction
class MakeWithdrawalButtonAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
// add code here to make the withdrawal
depositButton.setEnabled(true);
makeDepositButton.setEnabled(true);
} // end actionPerformed
} // end MakeWithDrawalButtonAction
class NextButtonAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
pinField.setText("");
pinField.requestFocus(true);
welcomeFrame.setVisible(false);
mainFrame.setVisible(true);
} // end actionPerformed
} // end NextButtonAction
class FinishButtonAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
outLabel.setText("");
mainFrame.setVisible(false);
inputFrame.setVisible(false);
welcomeFrame.setVisible(true);
pinField.requestFocus();
depositButton.setEnabled(true);
withdrawButton.setEnabled(true);
} // end actionPerformed
} // end FinishButtonAction
boolean isInputOK(String input) {
input = input.trim();
if( input.equals("") ) {
return false;
} // end if
int decimalIndex = input.indexOf(".");
if( decimalIndex == -1 ) {
return isAllDigits(input);
} else {
String first = input.substring(0,decimalIndex);
String last = input.substring(decimalIndex+1);
boolean firstAndLastAllDigits = isAllDigits(first) && isAllDigits(last);
boolean lastlengthOK = last.length() == 2;
return firstAndLastAllDigits && lastlengthOK;
} // end if
} // end is InputOK
boolean isAllDigits(String input) {
int index = 0;
while( index < input.length() ) {
if( ! Character.isDigit(input.charAt(index) ) ) {
return false;
} // end if
index++;
} // end while
return true;
} // end isAllDigits
boolean isAmountOK(double amount) {
if( amount <= 0.0 ) {
JOptionPane.showMessageDialog(null, "Enter an Positive Amount First");
return false;
} // end if
return true;
} // isAmountOK
void drawBalance(JLabel outLabel, BankAccount account) {
outLabel.setText("The balance is " + currency.format(theAccount.getBalance()) + ".");
} // end drawBalance
public static void main(String[] args) {
new ATM();
} // end main
} // end ATM
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.