In: Computer Science
Create an application to simulate a bank ATM and you must combine graphical interfaces using Swing or AWT and relational databases.
We will have a Bank Accounts database. Each account will have an account number, the name of the owner and the account balance.
The program must allow the following options:
a) Create an account: request the account information and save it in the database.
b) Enter the ATM: it will allow you to request the account number and will go to the next part of the program.
c) Close an account: delete it from the database
d) Exit
The second part of the program will perform the typical tasks of an ATM. It must perform the following:
a) See the account balance: Display the balance of the account. (The account has already been previously registered)
b) Deposit a money in the account: request the value to deposit and increase the balance in that value.
c) Withdraw money: request the value to be withdrawn, and if there is sufficient balance, this balance decreases in the value to be withdrawn.
d) Transfer money to another account: request the number of the other account and the value to be transferred, and if the other account exists and the balance is sufficient, decrease the source account by the indicated value and increase the balance of the other account by The transferred value.
e) Exit.
The program must be written in Java and you can use a desktop database (Access or H2 or Derby or Sqlite or HSQLDB) or a client-server database (MariaDB, MySQL or PostgreSQL).
Programming language: Java
import java.sql.*;
class Bank
{
//Need to declare all the variables required for opening account
private String accNo;
private String name;
private long balance;
Scanner acc=new Scanner(System.in);
//This method is for opening account
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc.oracle.thin:@localhost:1521:xe","system","oracle");
PreparedStatement stmt=new PreparedStatement("insert into Account values(?,?,?))";
System.out.println("Enter the account number");
accNo=acc.next();
stmt.setInt(1,accNo);
System.out.println("Enter the name");
name=acc.next();
stmt.setString(2,name);
System.out.println("Enter the balance");
balance=acc.nextLong();
stmt.setLong(3,balance);
int i=stmt.executeUpdate();
System.out.println(i+"accounts are inserted");
con.close();
}catch(Exception e)
{
System.out.println(e);
}
}
//This method to check the atm pin
public void checkPin()
{
Scanner pin=new Scanner(System.in);
//Here based on our choice we can read the pin number or can directly hard code the value
int pin=12345;
System.out.println("Welcome to the bank of ......");
System.out.prinln("Enter your pin");
int entry=pin.nextInt();
while(entry!=pin)
{
System.out.println("\n Incorrect pin try again..");
System.out.println("Enter your pin");
entry=pin.nextInt();
}
System.out.println("/n pin accepted select your options now");
}
//This method is to delete the account
public void deleteAccount()
int status=0;
Scanner pin=new Scanner(System.in);
System.out.println("Enter the account number to delete");
try
{
Connection con=Emp.getConnection();
PreparedStatement ps=con.prepareStatement("delete from emp where id=pin");
ps.setInt(1,accNum);
status=ps.executeUpdate();
con.close();
}
catch(Exception e)
{
e.printStatckTrace()'
}
return status;
}
//This method is for exit
public void exit()
{
System.out.println("Thank you for using ATM.... Have a nice day ....Good bye");
System.exit(0);
}
//This method for ATM operations
public void operations()
{
Scanner op=new Scanner("System.in");
int option;
do
{
System.out.println(" check balance" +\n +"deposit" + \n +"with draw" + \n +"Transfer money " +\n+ "Exit");
System.out.println("Enter your choice");
option=op.nextInt();
switch(option)
{
case 1: 999999999999
}