Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do I add an optional interest rate into my code as another option next to the withdraw and deposite bar? And I was told

How do I add an optional interest rate into my code as another option next to the withdraw and deposite bar? And I was told my method is outdated so how can I update it?

import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*;

class BankAccount implements ActionListener { RandomAccessFile file; DataInputStream din; DataOutputStream dout; JFrame bank; JPanel pnlp; JLabel lb; JFrame frmacc; JPanel pnlacc; JTextField tfacc,tfn,tfb,tft; JButton btacc;

JFrame frmv; JPanel pnlv; JScrollPane sp; JTable tbv;

JFrame frmd; JPanel pnld; JButton btd; JTextField tfd1,tfd2;

int f=0; private JMenuBar mbar; private JMenu file1; private JMenu transaction; private JMenuItem newacc; private JMenuItem search; private JMenuItem view; private JMenuItem exit; private JMenuItem withdraw; private JMenuItem deposit; JToolBar tb; JButton newac,searchac,exitac,helpac;

BankAccount() { bank=new JFrame("BANK ACCOUNT"); bank.setSize(650,400); bank.setVisible(true); bank.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

lb=new JLabel(); mbar=new JMenuBar(); bank.setJMenuBar(mbar); pnlp=new JPanel(new BorderLayout()); bank.setLayout(new BorderLayout());

file1=new JMenu("File"); mbar.add(file1); newacc=new JMenuItem("New Account"); file1.add(newacc); search=new JMenuItem("Search"); file1.add(search); view=new JMenuItem("View"); file1.add(view); exit=new JMenuItem("Exit"); file1.add(exit); transaction=new JMenu("Transaction"); mbar.add(transaction); withdraw=new JMenuItem("Withdraw"); transaction.add(withdraw); deposit=new JMenuItem("Deposit"); transaction.add(deposit); tb=new JToolBar(); bank.add(pnlp,"Center"); pnlp.add(tb,"North"); newacc.addActionListener(this); search.addActionListener(this); view.addActionListener(this); exit.addActionListener(this); withdraw.addActionListener(this); deposit.addActionListener(this); newac.addActionListener(this); searchac.addActionListener(this); exitac.addActionListener(this); bank.add(lb,"South"); }

public void actionPerformed(ActionEvent e) { if(e.getSource()==newac) { newAcc(); } if(e.getSource()==newacc) { newAcc(); }

if(e.getSource()==withdraw) { new Withdraw(frmacc,lb); }

if(e.getSource()==deposit) { new Deposit(frmacc,lb); }

if(e.getSource()==search) { new Search(frmacc,lb); }

if(e.getSource()==searchac) { new Search(frmacc,lb); }

if(e.getSource()==view) { try { view(); } catch (IOException e1) { e1.printStackTrace(); } }

if(e.getSource()==exit) { System.exit(0); }

if(e.getSource()==exitac) { System.exit(0); }

if(e.getSource()==btacc) { accCreate(); frmacc.dispose(); lb.setText("New Account Registration is Complete"); } }

private void view() throws IOException { frmv=new JFrame("Records"); frmv.setSize(600,350); frmv.setVisible(true); pnlv=new JPanel(new BorderLayout()); frmv.add(pnlv);

int i=0; String data[][]=new String[100][100]; String col[]={"AccNo","Name","Balance","Type"}; Boolean eof=false; try { din=new DataInputStream(new FileInputStream("Bank.txt"));

while(!eof) { try { while(true) { for(int j=0;j<=3;j++) { data[i][j]=din.readUTF(); } i++; } } catch(EOFException e) { eof=true; } catch (IOException e) { e.printStackTrace(); } } din.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } tbv=new JTable(data,col); sp=new JScrollPane(tbv); pnlv.add(sp);

lb.setText("Records"); }

private void newAcc() { frmacc=new JFrame("New Account"); frmacc.setSize(530,120); frmacc.setVisible(true); pnlacc=new JPanel(new FlowLayout()); frmacc.add(pnlacc); pnlacc.add(new JLabel("Name:")); tfn=new JTextField(8); pnlacc.add(tfn); pnlacc.add(new JLabel("Balance:")); tfb=new JTextField(8); pnlacc.add(tfb); pnlacc.add(new JLabel("Type of Account:")); tft=new JTextField(8); pnlacc.add(tft);

btacc=new JButton("Ok"); pnlacc.add(btacc);

btacc.addActionListener(this); lb.setText("Processing New Account..."); }

private void accCreate() { try { file=new RandomAccessFile("Bank.txt","rw"); file.seek(file.length()); int accno=(int)(Math.random()*10000); String acc=Integer.toString(accno); String name=tfn.getText(); String bal=tfb.getText(); String ty=tft.getText(); if(ty.equals("savings")) { if(Double.parseDouble(bal)>1500){ file.writeUTF(acc); file.writeUTF(name); file.writeUTF(bal); file.writeUTF(ty); JOptionPane.showMessageDialog(frmacc, "Account No: "+acc+" is Registered"); } else { JOptionPane.showMessageDialog(frmacc, "Minimum Balance must be $1500"); } } else if(ty.equals("checking")) { if(Double.parseDouble(bal)>200) { file.writeUTF(acc); file.writeUTF(name); file.writeUTF(bal); file.writeUTF(ty); JOptionPane.showMessageDialog(frmacc, "Account No: "+acc+" is Registered"); } else { JOptionPane.showMessageDialog(frmacc, "Minimum Balance must be $200"); } } else { JOptionPane.showMessageDialog(frmacc, "Invalid Account Type"); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }

public class main { JFrame f; public static void main(String[] args) throws IOException { SwingUtilities.invokeLater(new Runnable(){ public void run() { new BankAccount(); } }); } }

/////////

import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*;

public class Deposit implements ActionListener { private JButton btd; private JFrame frmd; private JPanel pnld; private JTextField tfd1; private JTextField tfd2;

DataInputStream din; DataOutputStream dout; String data[][]=new String[100][100]; int i=0; private String acc; private double amt; private String amount; JFrame frmacc; JLabel lb;

Deposit(JFrame frmacc, JLabel lb) { this.frmacc=frmacc; this.lb=lb; frmd = new JFrame("Withdraw"); frmd.setSize(200,140); frmd.setVisible(true);

pnld = new JPanel(new FlowLayout()); frmd.add(pnld); pnld.add(new JLabel("Account No:")); tfd1 = new JTextField(8); pnld.add(tfd1); pnld.add(new JLabel("Amount:")); tfd2 = new JTextField(8); pnld.add(tfd2);

btd=new JButton("Ok"); pnld.add(btd); btd.addActionListener(this); lb.setText("Deposit is Processing..."); }

@Override public void actionPerformed(ActionEvent e) { Object obj = e.getSource(); if(obj==btd) { fillArray(); getdata(); depositMoney(); frmd.dispose(); lb.setText("WithDrawal is Complete"); } }

private void getdata() { acc=tfd1.getText(); amount=tfd2.getText(); amt=Double.parseDouble(amount); }

private void fillArray() { Boolean eof=false;

try { din=new DataInputStream(new FileInputStream("Bank.txt"));

while(!eof) { try { while(true) { for(int j=0;j<=3;j++) { data[i][j]=din.readUTF(); } i++; } } catch(EOFException e) { eof=true; } catch (IOException e) { e.printStackTrace(); } }

try { din.close(); } catch (IOException e) { e.printStackTrace(); } } catch (FileNotFoundException e) { e.printStackTrace(); } }

private void depositMoney() { int x=0,f=0; while(x

if(f==0) { JOptionPane.showMessageDialog(frmacc,"Account No is non-Existent"); } if(f==1) { try { writeFile(); } catch (IOException e) { e.printStackTrace(); } } }

private void writeFile() throws IOException { int x,y; dout=new DataOutputStream(new FileOutputStream("Bank.txt")); for(x=0;x

//////////

import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*;

public class Search implements ActionListener { DataInputStream din; DataOutputStream dout; String data[][]=new String[100][100]; int i=0; private JFrame bank; private JFrame frms; private JPanel pnls; private JTextField tfs; private JButton bts; private String acc; private JFrame frmsd; private JPanel pnlsd; private JTextField tfacc; private JTextField tfn; private JTextField tfb; private JTextField tft; private JButton btsd; JLabel lb;

public Search(JFrame frmacc, JLabel lb) { bank=frmacc; this.lb=lb; frms=new JFrame("Search"); frms.setSize(220,120); frms.setVisible(true); pnls=new JPanel(new FlowLayout()); frms.add(pnls); pnls.add(new JLabel("Account No:")); tfs=new JTextField(8); pnls.add(tfs); bts=new JButton("Ok"); pnls.add(bts); bts.addActionListener(this); lb.setText("Searching..."); }

@Override public void actionPerformed(ActionEvent e) { Object obj = e.getSource(); if(obj==bts) { fillArray(); getData(); display(); } if(obj==btsd) { frmsd.dispose(); frms.dispose(); lb.setText("Search is Complete"); } }

private void display() { frmsd=new JFrame("Display"); frmsd.setSize(200,220); frmsd.setVisible(true); pnlsd=new JPanel(new FlowLayout()); frmsd.add(pnlsd); pnlsd.add(new JLabel("Account No:")); tfacc=new JTextField(8); pnlsd.add(tfacc); pnlsd.add(new JLabel("Name:")); tfn=new JTextField(8); pnlsd.add(tfn); pnlsd.add(new JLabel("Balance:")); tfb=new JTextField(8); pnlsd.add(tfb); pnlsd.add(new JLabel("Type of Account:")); tft=new JTextField(8); pnlsd.add(tft);

btsd=new JButton("Ok"); pnlsd.add(btsd);

btsd.addActionListener(this); searchPerson(); }

private void searchPerson() { int x=0,f=0; while(x

private void getData() { acc=tfs.getText(); }

private void fillArray() { Boolean eof=false;

try { din=new DataInputStream(new FileInputStream("Bank.txt"));

while(!eof) { try { while(true) { for(int j=0;j<=3;j++) { data[i][j]=din.readUTF(); } i++; }

} catch(EOFException e) { eof=true; } catch (IOException e) { e.printStackTrace(); } }

try { din.close(); } catch (IOException e) { e.printStackTrace(); } } catch (FileNotFoundException e) { e.printStackTrace(); } } }

/////////////

import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*;

public class Withdraw implements ActionListener {

private JFrame frmacc; private JFrame frmw; private JPanel pnlw; private JTextField tfw1; private JTextField tfw2; private JButton btw;

DataInputStream din; DataOutputStream dout; String data[][]=new String[100][100]; int i=0; private String acc; private String amount; private double amt; JLabel lb;

public Withdraw(JFrame frmacc, JLabel lb) { this.frmacc=frmacc; this.lb=lb;

frmw = new JFrame("Withdraw"); frmw.setSize(200,140); frmw.setVisible(true);

pnlw = new JPanel(new FlowLayout()); frmw.add(pnlw); pnlw.add(new JLabel("Account No:")); tfw1 = new JTextField(8); pnlw.add(tfw1); pnlw.add(new JLabel("Amount:")); tfw2 = new JTextField(8); pnlw.add(tfw2);

btw=new JButton("Ok"); pnlw.add(btw); btw.addActionListener(this); lb.setText("WithDrawal is Processing..."); }

@Override public void actionPerformed(ActionEvent e) { Object obj = e.getSource(); if(obj==btw){ fillArray(); getdata(); withdrawMoney(); frmw.dispose(); lb.setText("WithDrawal is Complete"); } }

private void withdrawMoney() { int x=0,f=0; while(x1500) { bal=bal-amt; } else { JOptionPane.showMessageDialog(frmacc, "Minimum Balance $1500. Withdrawal cannot be made"); } } else if(ty.equals("checking")) { if((bal-amt)>200) { bal=bal-amt; } else { JOptionPane.showMessageDialog(frmacc, "Minimum Balance $200. Withdrawal cannot be made"); } } data[x][2]=Double.toString(bal); f=1; } x++; }

if(f==0) { JOptionPane.showMessageDialog(frmacc,"Account No is non-Existent"); }

if(f==1) { try { writeFile(); } catch (IOException e) { e.printStackTrace(); } } }

private void writeFile() throws IOException { int x,y; dout=new DataOutputStream(new FileOutputStream("Bank.txt")); for(x=0;x

private void getdata() { acc=tfw1.getText(); amount=tfw2.getText(); amt=Double.parseDouble(amount); }

private void fillArray() { Boolean eof=false;

try { din=new DataInputStream(new FileInputStream("Bank.txt"));

while(!eof) { try { while(true) { for(int j=0;j<=3;j++) { data[i][j]=din.readUTF(); } i++; } } catch(EOFException e) { eof=true; } catch (IOException e) { e.printStackTrace(); } }

try { din.close(); } catch (IOException e) { e.printStackTrace(); } } catch (FileNotFoundException e) { e.printStackTrace(); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

More Books

Students also viewed these Databases questions

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago