Jeun 0 Newbie Poster

/*None of the buttons except create and clear work can someone help please , can anyone help me with the parts i have missing , the account and date test class work fine i just need the bank account GUI to work properly , here is a detailed explanation of what the program should do

Bank account GUI
Add a new Account
• Display information on an account neatly (search using account number). Having located an account one could update or delete it.
• Display all accounts held by a customer, one at a time (search using name). You could press next to see the next account for that person. Having located a particular account one could update or delete it.
• Delete an account entirely
• Update the account information
• Add monthly interest to all accounts.
• Print information for all accounts neatly, with appropriate headers, to a tab separated file, readable by a spreadsheet such as Excel or OpenOffice Calc.
• Exit the system
*/


/////account class\\\\\\\

public class Account {
  // Instance variable 
  private double balance;
  
  String acctNumber ; 

   String dateOpened;
   String custID ; 
   int amountInArray;

  // Constructor 1 (for initial deposit accounts)
  public Account(String acctNum , double bal , String date , String custid) {
           acctNumber = acctNum;
           balance = bal ; 
           date = dateOpened ; 
           custID = custid ; 
  }


 //get the account number
 public String getacctNumber() {
    return acctNumber;
  }
  
  
   //get the account number
 public String getcustid() {
    return custID;
  }

  //get account balance
  public double getBalance() {
    return balance;
  }
  
    public String getacctDate() {
    return dateOpened;
  }
   //close account

}

////////date test class\\\\\\\\

import java.text.SimpleDateFormat;
import java.text.ParseException;

public class DateTest {

  public boolean isValidDate(String inDate) {

    if (inDate == null)
      return false;

    //set the format to use as a constructor argument
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    
    if (inDate.trim().length() != dateFormat.toPattern().length())
      return false;

    dateFormat.setLenient(false);
    
    try {
      //parse the inDate parameter
      dateFormat.parse(inDate.trim());
    }
    catch (ParseException pe) {
      return false;
    }
    return true;
    
 
  }
 
  
}

//////////////Bank account\\\\\\\\\\\\\\\\

import java.awt.*;
import java.awt.event.*;
import java.text.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.Arrays;
import java.io.*;

public class BankAccount extends JFrame {

    // Make these variables publicly available
    
   
    String file =  ("THUS.txt");
   
    public static String acctNumber ;
    public static String  custid , acctDateOpened;
    public static double balance ;
   
    boolean valid1, valid2, valid3, valid4, valid5, valid6, valid7 ;
    
    int i = 0; 
    Account [] account = new Account [i]; 
     
 
    
 
  
    // Setup Arrays for each account
    
    
    // JPanel for user inputs
    private JPanel inputDetailJPanel;

    
    // JLabel and Jtext field for custID
    private JTextField acctDateOpenedJTextField;
    private JLabel acctDateOpenedJLabel;
    
    // JLabel and Jtext field for custID
    private JTextField custidJTextField;
    private JLabel custidJLabel;
    
    // JLabel and JTextField for account number
    private JLabel acctNumberJLabel;
    private JTextField acctNumberJTextField;

    // JLabel and JTextField for balance
    private JLabel balanceJLabel;
    private JTextField balanceJTextField;


    // JButton to create account
    private JButton CreateAccountJButton;
    
    //JButton for update
    private JButton updateJButton ; 
    
    //JButton for update
    private JButton interestJButton ; 
    

    //JButton to clear account 
    private JButton clearJButton ; 

    
    
    // JButton to delete account
    private JButton DeleteAccountJButton;

    // initialise display account 
    private JButton displayAccountJButton ; 
    
    
    // JLabel and JTextArea to display account details
    private JLabel displayJLabel;
    private JTextArea displayJTextArea;
    
   



    // constructor
    public BankAccount() {
        createUserInterface();
    }

    // create and position GUI components; register event handlers
    private void createUserInterface() {
        // get content pane for attaching GUI components
        Container contentPane = getContentPane();

        // enable explicit positioning of GUI components
        contentPane.setLayout(null);

        // set up inputDetailJPanel
        inputDetailJPanel = new JPanel();
        inputDetailJPanel.setBounds(31, 31, 215, 323); // 3rd number controlds length , 4th width 
        inputDetailJPanel.setBorder(new TitledBorder("Account"));
        inputDetailJPanel.setLayout(null);
        contentPane.add(inputDetailJPanel);

        // set up custIDJLabel
        custidJLabel = new JLabel();
        custidJLabel.setBounds(8, 32, 90, 23);
        custidJLabel.setText("customer ID");
        inputDetailJPanel.add(custidJLabel);

        // set up cusidJTextField
        custidJTextField = new JTextField();
        custidJTextField.setBounds(104, 32, 88, 21);
        custidJTextField.setHorizontalAlignment(JTextField.RIGHT);
        inputDetailJPanel.add(custidJTextField);
        
        
        
        // set up AccountnumJLabel
        acctNumberJLabel = new JLabel();
        acctNumberJLabel.setBounds(8, 56, 100, 23);
        acctNumberJLabel.setText("Account Number:");
        inputDetailJPanel.add(acctNumberJLabel);

        // set up AccountnumTextField
        acctNumberJTextField = new JTextField();
        acctNumberJTextField.setBounds(112, 56, 80, 21);
        acctNumberJTextField.setHorizontalAlignment(JTextField.RIGHT);
        inputDetailJPanel.add(acctNumberJTextField);

        // set up BalanceJLabel
        balanceJLabel = new JLabel();
        balanceJLabel.setBounds(8, 80, 60, 23);
        balanceJLabel.setText("Balance:");
        inputDetailJPanel.add(balanceJLabel);

        // set up BalanceTextField
        balanceJTextField = new JTextField();
        balanceJTextField.setBounds(112, 80, 80, 21);
        balanceJTextField.setHorizontalAlignment(JTextField.RIGHT);
        inputDetailJPanel.add(balanceJTextField);
        
        // set up DateJLabel
        acctDateOpenedJLabel = new JLabel();
        acctDateOpenedJLabel.setBounds(8, 100, 80, 24);
        acctDateOpenedJLabel.setText("Date:");
        inputDetailJPanel.add(acctDateOpenedJLabel);

        // set up dateTextField
        acctDateOpenedJTextField = new JTextField();
        acctDateOpenedJTextField.setBounds(114, 105, 80, 21);
        acctDateOpenedJTextField.setHorizontalAlignment(JTextField.RIGHT);
        inputDetailJPanel.add(acctDateOpenedJTextField);


        // set up CreateAccountButton
        CreateAccountJButton = new JButton();
        CreateAccountJButton.setBounds(112, 152, 80, 26);
        CreateAccountJButton.setText("Create");
        inputDetailJPanel.add(CreateAccountJButton);
        CreateAccountJButton.addActionListener(

        new ActionListener() {
            // event handler called when CreateAccountJButton
            // is clicked
            public void actionPerformed(ActionEvent event) {
                CreateAccountJButtonActionPerformed(event);
            }

        }

        ); // end call to addActionListener
        
         // set up interesrAccountButton
        interestJButton = new JButton();
        interestJButton.setBounds(32, 238, 160, 28);
        interestJButton.setText("intrest");
        inputDetailJPanel.add(interestJButton);
        interestJButton.addActionListener(

        new ActionListener() {
            // event handler called when interestAccountJButton
            // is clicked
            public void actionPerformed(ActionEvent event) {
                interestJButtonActionPerformed(event);
            }

        }

        ); // end call to addActionListener

        // set up DeleteAccountButton
        DeleteAccountJButton = new JButton();
        DeleteAccountJButton.setBounds(16, 152, 80, 24);
        DeleteAccountJButton.setText("Delete");
        inputDetailJPanel.add(DeleteAccountJButton);
        DeleteAccountJButton.addActionListener(

        new ActionListener() // anonymous inner class
                {
                    // event handler called when DeleteAccountJButton
                    // is clicked
                    public void actionPerformed(ActionEvent event) {
                    DeleteAccountJButtonActionPerformed(event);

                    }

                }

                ); // end call to addActionListener

       
                
                
                
         // set up updateJButton
        updateJButton = new JButton();
        updateJButton.setBounds(16, 180, 176, 24);
        updateJButton.setText("update Account ");
        inputDetailJPanel.add(updateJButton);
        updateJButton.addActionListener(

        new ActionListener() // anonymous inner class
                {
                    // event handler called when TransactionJButton
                    // is clicked
                    public void actionPerformed(ActionEvent event) {
                        updateJButtonActionPerformed(event);
                    }

                } // end anonymous inner class

                );
                
        // clear Button          
        clearJButton = new JButton();
        clearJButton.setBounds(18, 210, 176, 24);
        clearJButton.setText("clear");
        inputDetailJPanel.add(clearJButton);
        clearJButton.addActionListener(

        new ActionListener() // anonymous inner class
                {
                    // event handler called when clearJButton
                    // is clicked
                    public void actionPerformed(ActionEvent event) {
                        clearJButtonListenerActionPerformed(event);
                    }

                } // end anonymous inner class

                );
                
                
                

        // set up displayJLabel
        displayJLabel = new JLabel();
        displayJLabel.setBounds(250, 26, 190, 33);
        displayJLabel.setText("Account Details:");
        contentPane.add(displayJLabel);

        // set up displayJTextArea
        displayJTextArea = new JTextArea();
        displayJTextArea.setBounds(260, 68, 422, 205);
        displayJTextArea.setEditable(false);
        contentPane.add(displayJTextArea);

        // set properties of application's window
        setTitle("Bank Accounts"); // set title bar string
        setSize(750, 450); // set window size
        setVisible(true); // display window
        
        
        // set up CreateAccountButton
        displayAccountJButton = new JButton();
        displayAccountJButton.setBounds(42, 238, 140, 58);
        displayAccountJButton.setText("Search");
        inputDetailJPanel.add(displayAccountJButton);
        displayAccountJButton.addActionListener(

        new ActionListener() {
            // event handler called when CreateAccountJButton
            // is clicked
            public void actionPerformed(ActionEvent event) {
                displayAccountJButtonActionPerformed(event);
            }

        }

        ); // end call to addActionListener

    } // end method createUserInterface
    
    

    private void CreateAccountJButtonActionPerformed(ActionEvent event) {
                
                
              //increment number in array 
              
               i ++ ;
                     
              Account [] newaccount = new Account [i] ;
              System.arraycopy(account, 0, newaccount, 0, account.length);
              account=newaccount;
              
         
               balance = Double.parseDouble(balanceJTextField.getText());
               custid = custidJTextField.getText();
               custid = custid.trim();
               acctDateOpened = acctDateOpenedJTextField.getText();
               acctDateOpened = acctDateOpened.trim(); 
               acctNumber = acctNumberJTextField.getText();
               acctNumber = acctNumber.trim();
 
 
              // Check to see if each account array is populated and
             // if not add account details
            if (balance == 0 )
             {
               JOptionPane.showMessageDialog (null, "you initial balance cannot be zero ");
               valid1 = false ;
                         }
              else valid1 = true ;
 
 
 
                  if (balance < 0 )
                        {
                          valid2 = false;
                        JOptionPane.showMessageDialog (null, "Please enter a number for account balance!");
                         }
                      else valid2 = true;
 
 
                    DateTest test = new DateTest();
                   if (acctDateOpened.length() == 0 || test.isValidDate(acctDateOpened)== false)
                        {
                            JOptionPane.showMessageDialog (null, "Enter Account date in correct dd/mm/yyyy format");
                           valid3 = false;
                               }
                             else
                             valid3 = true;
 
                             if (custid.length() != 7)
                                {
                            JOptionPane.showMessageDialog (null, "Please enter apositive 7 digit id number");
                       valid4 = false;
                             }
                         else
                     valid4 = true;
 
                        //validate customer id number
 
                        for (int i = 0; i < custid.length(); i++)
                            {
                              if (!Character.isDigit(custid.charAt(i)))
                                {
                           valid5 = false;
                           JOptionPane.showMessageDialog (null, "Please enter a positive 7 digit id number");
                                }
                       else valid5 = true;
                          }
 
 
                    if (acctNumber.length() == 0)
                      {
                    JOptionPane.showMessageDialog (null, "Please enter an account number");
                    valid6 = false;
                         }
                            else
                                valid6 = true;
 
                           // validate account number is a number
for (int i = 0; i < acctNumber.length(); i++)
{
if (!Character.isDigit(acctNumber.charAt(i)))
{
valid7 = false;
JOptionPane.showMessageDialog (null, "Please enter a number for account number");
}
else valid7 = true;
 
}
 
 
 
 
 
if (valid1 == true && valid2 == true && valid3== true && valid4 ==true && valid5 == true && valid6 == true && valid7 == true )
{
 
 
try {
 
 
 
FileWriter fw = new FileWriter (file, true);
BufferedWriter bw = new BufferedWriter (fw);
PrintWriter outFile = new PrintWriter (bw);
account[i-1] = new Account ( acctNumber , balance , acctDateOpened , custid ) ;
outFile.println ("account number " + account[i-1].getacctNumber() );
outFile.println ("balance " + account[i-1].getBalance () );
outFile.println ("date opened " + account[i-1].getacctDate () );
outFile.println ("customer ID " + account[i-1].getcustid () );
outFile.println();
outFile.close();
JOptionPane.showMessageDialog (null, "Account has been saved at: " + file);
 
 
 
 
 
}
 
catch (Exception e) {
 
JOptionPane.showMessageDialog(null, "Error: File not found");
}
 
//Account acc =account[i-1];
displayJTextArea.setText( "Account Number customerID Date Of Opening balance" + " \n " + account[i-1] + " " + account[i-1].getacctNumber() + " " + account[i-1].getBalance () + " " + account[i-1].getacctDate () + " " + account[i-1].getcustid () );
 
 
 
}
 
}
    
     private void clearJButtonListenerActionPerformed(ActionEvent  event)
        {
           
                
               
                custidJTextField.setText("  ");
             
                acctDateOpenedJTextField.setText(" ");
           
                acctNumberJTextField.setText(" ");
            
                balanceJTextField.setText(" ");
            
        }
        
         private void interestJButtonActionPerformed(ActionEvent  event)
        {
           
               
             
            double  add  =  Double.parseDouble ( JOptionPane.showInputDialog ("enter percentage interest") ) ;
            for (int i = 0; i < account.length; i++) 
                { 
             
               double  B = account[i - 1].getBalance();
               
               double amount  = (add/100) * B; 
               balance  += amount ;
               
              }
            
                
            }
            
            
                  private void displayAccountJButtonActionPerformed(ActionEvent  event)
        {
           
               
             
            String searchAccount =  JOptionPane.showInputDialog (null, "Please enter the account number to search");
            for (int d = 0; i < account.length; d++) 
                { 
             
                    if ( searchAccount.equals(account[i-1].getacctNumber() ) ) 
                      {    displayJTextArea.setText( account[i-1].getacctNumber() ) ; 
                           displayJTextArea.setText( account[i-1].getcustid() ) ;
                           displayJTextArea.setText( " " + account[i-1].getBalance () ) ; 
                           displayJTextArea.setText( account[i-1].getacctDate () ) ; 
                           
                        }
                        else {
                          d++;
                        }
                        
                        if (d ==account.length)
                    JOptionPane.showMessageDialog(null, "ACCOUNT NOT FOUND");
               
         
               
              }
            
                
            }
        
        

    private void DeleteAccountJButtonActionPerformed(ActionEvent event) {
        
        
        String D =  JOptionPane.showInputDialog (null, "Please enter the account number to delete the account");
        
        for ( int c = 0 ; c < account.length; c++ ) 
        {  
            if(  D.equals( account[i].getacctNumber()) )
              { 
                  JOptionPane.showMessageDialog (null , "FOUND");
                  account[i] = null ; 
                } else 
                   { JOptionPane.showMessageDialog (null, "NOT FOUND ");
                    } 
                
            }  
               
            


        } 

        
        
      
    
    

    private void updateJButtonActionPerformed(ActionEvent event) {  
        
        
        
        

    }

   

    public static void main(String[] args) {
        // Populate arrays with the word EMPTY
        // so we can check to see if the values are empty later
       
       

        BankAccount application = new BankAccount();
        application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

}