Credit card, Banking, Investments, Cd accounts, Savings account, Loan , Auto Loans

Write a java application?

3.Assume that a bank maintains 2 kinds of account for its customers, one called savings account and the other current account. The saving account provides compound interest and withdraw facilities but no cheque book facility, the current account provides cheque book facility but no interest current account holders should also maintain minimum balance and if the balance falls below this level, a service charge is imposed.
Create a class account that stores customers name, account number and type of account. From this, derive the class cur-acct and sav-acct to make them more specific to their requirements. Include the necessary methods in order to achieve the following tasks.
(1)Accept deposit from a customer and update the balance.
(2)Display the balance.
(3)Compute and deposit interest.
(4)Permit withdrawal and update the balance.
(5)Check for the minimum balance, impose penalty, if necessary and update the balance.
Use constructors and methods to initialize the class

import java.io.*;
import java.util.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;
import java.sql.*;
import javax.swing.*;
public class bank extends JFrame implements ActionListener
{
static String cname;
static int ch,i=1;
static int caccno;
static Connection con=null;
static Statement st=null;
static ResultSet rs=null;
static PreparedStatement pst;
Calendar cal1=Calendar.getInstance();
JTextField t1,t2,t3,t4;
JLabel l1,l2,l3,l4;
JButton cb,ct,rp;
JLabel day;
JFrame f1;
JPanel p1;
JButton add,mod,save,del,sch,n1,n2,n3,n4;
JFrame f2=new JFrame();
JPanel p2=new JPanel();
JFrame f3=new JFrame();
JPanel p3=new JPanel();
JLabel fl1=new JLabel(“Customer Account No.:”);
JLabel f3l1=new JLabel(“Customer Account No.:”);
JLabel fl2=new JLabel(“Customer Name:”);
JButton f3b1=new JButton(“OK”);
static JTextField ft1=new JTextField(15);
static JTextField f3t1=new JTextField(15);
static JTextField ft2=new JTextField(15);
public bank()
{
f1=new JFrame(“sat”);
p1=new JPanel();

//day.setText(Integer.toString(cal1.get(Calendar.DATE))+”-”+Integer.toString(cal1.get(Calendar.MONTH))+”-”+Integer.toString(cal1.get(Calendar.YEAR)));
getContentPane().add(p1);
p1.setLayout(null);
cb=new JButton(“Customer Details”);
cb.setBounds(100,100,400,50);
cb.addActionListener(this);
p1.add(cb);
ct=new JButton(“Customer Transaction Details”);
ct.setBounds(100,200,400,50);
ct.addActionListener(this);
p1.add(ct);
rp=new JButton(“Report”);
rp.setBounds(100,300,400,50);
rp.addActionListener(this);
p1.add(rp);
setDefaultCloseOperation(f1.EXIT_ON_CLOSE);
setSize(600,500);
setLocation(200,100);
setVisible(true);
}
static int opendatabase()
{
try
{
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
con=DriverManager.getConnection(“jdbc:odbc:dsn2″);
st=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs=st.executeQuery(“select * from cdetails”);
//ft1.setText(rs.getString(2));
return 0;
}
catch(Exception e)
{
System.out.println(e.getMessage());
return -1;
}
}
public void actionPerformed(ActionEvent e1)
{
Object o=e1.getSource();
if(o==add)
{

ft1.requestFocus();
ft2.transferFocus();
ft1.setText(“”);
ft2.setText(“”);
save.setEnabled(true);
mod.setEnabled(false);
del.setEnabled(false);
sch.setEnabled(false);
ch=1;
}
if(o==save)
{

add.setEnabled(true);
save.setEnabled(false);
mod.setEnabled(true);
del.setEnabled(true);
sch.setEnabled(true);
try
{
if(opendatabase()==-1)
{
System.out.println(“Unable to connect to the database”);
}
else
{
caccno=Integer.parseInt(ft1.getText());
cname=ft2.getText();
if(ch==3)
{
st=con.createStatement();
st.executeUpdate(“update cdetails set cname=’”+cname+”‘ where cacctno=”+caccno+”");
}
else
{
pst=con.prepareStatement(“insert into cdetails values(?,?)”);
pst.setInt(1,caccno);
pst.setString(2,cname);
pst.executeUpdate();
}
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
ch=2;
}
if(o==mod)
{

add.setEnabled(false);
save.setEnabled(true);
mod.setEnabled(false);
del.setEnabled(false);
sch.setEnabled(true);
ch=3;
}
if(o==sch)
{
try
{
if(opendatabase()==-1)
{
System.out.println(“Unable to connect to the database”);
}
else
{
String inputvalue = JOptionPane.showInputDialog(“Please input a value”);
add.setEnabled(true);
save.setEnabled(false);
mod.setEnabled(true);
del.setEnabled(true);
sch.setEnabled(true);
rs=st.executeQuery(“select * from cdetails”);
while(rs.next())
{
String s3=rs.getString(1);
if(inputvalue.equalsIgnoreCase(s3))
{
ft1.setText(s3);
ft2.setText(rs.getString(2));
ch=10;
break;
}
if(ch==10)
//JOptionPane.showMessageDialog(this,new String(“Found”),”Message”,JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(this,new String(“Not Found”),”Message”,JOptionPane.INFORMATION_MESSAGE);
}
}
}
catch(Exception e)
{
System.out.println(e);
}
ch=4;
}
if(o==del)
{

add.setEnabled(true);
save.setEnabled(false);
mod.setEnabled(true);
del.setEnabled(false);
sch.setEnabled(true);
try
{
if(opendatabase()==-1)
{
System.out.println(“Unable to connect to the database”);
}
else
{
caccno=Integer.parseInt(ft1.getText());
st=con.createStatement();
st.executeUpdate(“delete * from cdetails where cacctno=”+caccno+”");
ft1.setText(“”);
ft2.setText(“”);
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
ch=5;
}
if(o==n1)
{
try
{
opendatabase();
rs.first();
ft1.setText(rs.getString(1));
ft2.setText(rs.getString(2));

}
catch(Exception e)
{
n1.setEnabled(false);
}
}
if(o==n2)
{
try
{
n3.setEnabled(true);
rs.previous();
ft1.setText(rs.getString(1));
ft2.setText(rs.getString(2));
if(rs.isFirst())
n2.setEnabled(false);
}
catch(Exception e)
{
n2.setEnabled(false);
}
}
if(o==n3)
{

try
{
n2.setEnabled(true);
rs.next();
ft1.setText(rs.getString(1));
ft2.setText(rs.getString(2));
if(rs.isLast())
n3.setEnabled(false);

}
catch(Exception e)
{
n3.setEnabled(false);
}
}
if(o==n4)
{

try
{
opendatabase();
rs.last();
ft1.setText(rs.getString(1));
ft2.setText(rs.getString(2));

}
catch(Exception e)
{
n4.setEnabled(false);
System.out.println(e);
}
}
if(o==ct)
{
JFrame f2=new JFrame();
JPanel p2=new JPanel();
f2.getContentPane().add(p2);
f2.setDefaultCloseOperation(f1.EXIT_ON_CLOSE);
f2.setSize(200,200);
f2.setVisible(true);
}
if(o==cb)
{

f2.getContentPane().add(p2);
p2.setLayout(null);
add=new JButton(“ADD”);
add.setBounds(370,50,100,30);
add.addActionListener(this);
p2.add(add);
save=new JButton(“SAVE”);
save.setBounds(370,100,100,30);
save.setEnabled(false);
save.addActionListener(this);
p2.add(save);
mod=new JButton(“MODIFY”);
mod.setBounds(370,150,100,30);
mod.addActionListener(this);
p2.add(mod);
sch=new JButton(“SEARCH”);
sch.setBounds(370,200,100,30);
sch.addActionListener(this);
p2.add(sch);
del=new JButton(“DELETE”);
del.setBounds(370,250,100,30);
del.addActionListener(this);
p2.add(del);
n1=new JButton(“<<-");
n1.setBounds(30,250,80,30);
n1.addActionListener(this);
p2.add(n1);
n2=new JButton("<-");
n2.setBounds(100,250,80,30);
n2.addActionListener(this);
p2.add(n2);
n3=new JButton("->“);
n3.setBounds(170,250,80,30);
n3.addActionListener(this);
p2.add(n3);
n4=new JButton(“->>”);
n4.setBounds(240,250,80,30);
n4.addActionListener(this);
p2.add(n4);
fl1.setBounds(10,50,200,50);
p2.add(fl1);
fl2.setBounds(10,100,250,50);
p2.add(fl2);
ft1.setBounds(150,70,200,20);
p2.add(ft1);
ft2.setBounds(150,120,200,20);
p2.add(ft2);
setDefaultCloseOperation(f2.EXIT_ON_CLOSE);
f2.setSize(500,500);
f2.setLocation(100,100);
f2.setVisible(true);
}
}
public static void main(String s[])
{
new bank();
}
}

Google I/O 2009 – thoughtworks on App Engine for Java..