Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import java.util.Scanner;
- public class Services extends Account{
- static int acc_count=0;
- static int initial_id=100001;
- static boolean sender_correct=false, receiver_correct=false,exit=false,l,w;
- public static void existingCustomer(int cid) throws ClassNotFoundException,SQLException
- {
- Scanner in=new Scanner(System.in);
- Class.forName("oracle.jdbc.driver.OracleDriver");
- String url="jdbc:oracle:thin:@localhost:1521:xe";//major protocol: minor protocol/Ip address:Portno:SID-> (here loacl :xe)
- String userName="System";
- String password="desire";
- ResultSet rs;
- int acc_id=0;
- Connection con=DriverManager.getConnection(url,userName,password);
- Statement s=con.createStatement();
- String query="select * from bank where id="+cid;
- rs=s.executeQuery(query);
- if(rs.next())
- {
- int ac=rs.getInt("status");
- if(ac!=1)
- {
- System.out.println("Services with this account is temporarly suspended..");
- return;
- }
- System.out.println("Enter password:");
- String pass=in.next();
- String upass=rs.getString("password");
- if(pass.equals(upass))
- {
- acc_id=rs.getInt(1);
- }
- else
- {
- System.out.println("Invalid password");
- return;
- }
- }
- else
- {
- System.out.println("No Account with such account");
- return;
- }
- Account sender=new Account();
- Account receiver=new Account();
- String type;
- double amt;
- boolean flag=false;
- do
- {
- System.out.println("1.Deposit Money\n2.Withdraw Money\n3.Fund Transfer\n4.Deactivate Account\n5.Account Informatoin\n6.Exit\n");
- System.out.println("Enter your choice:");
- int input=in.nextInt();
- switch(input)
- {
- case 1:
- if(acc_id!=0)
- {
- System.out.println("Enter the ammount to deposite;");
- double deposite_amt=in.nextDouble();
- try{
- l=Account.addBalance(acc_id,deposite_amt);
- }catch (Exception e)
- {
- e.printStackTrace();
- }
- if(l)
- System.out.println("Ammount added sucessfully!");
- }
- break;
- case 2: if(acc_id!=0)
- {
- System.out.println("Enter the ammount to withdraw;");
- double withdraw_amt=in.nextDouble();
- try
- {
- w=Account.withdrawBalance(acc_id,withdraw_amt);
- }catch(Exception e)
- {
- e.printStackTrace();
- }
- if(w)
- System.out.println("Ammount withdrawn sucessfully!");
- }
- break;
- case 3: if(acc_id!=0)
- {
- System.out.println("Enter your Receiver id:");
- int receiver_id=in.nextInt();
- String fquery="select id from bank where id="+receiver_id;
- ResultSet rs1=s.executeQuery(fquery);
- if(rs1.next())
- {
- System.out.println("Enter the ammount to transfer");
- double transfer_amt=in.nextDouble();
- try{
- if(Account.checkBalance(acc_id)>transfer_amt)
- {
- Account.addBalance(rs1.getInt(1),transfer_amt);
- Account.withdrawBalance(acc_id,transfer_amt);
- }
- else
- {
- System.out.println("Insufficent Balance");
- }
- }catch(Exception e)
- {
- e.printStackTrace();
- }
- }
- else
- {
- System.out.println("No Account with such id");
- }
- }
- break;
- case 4:
- if(acc_id!=0)
- try{
- Account.deactivate(acc_id);
- }catch(Exception e)
- {
- e.printStackTrace();
- }
- break;
- case 5:
- try{
- Account.showAccountInfo(acc_id);
- }catch (Exception e) {
- e.printStackTrace();
- }
- break;
- case 6:exit=true;
- break;
- }
- }while(!exit);
- }
- public static boolean newCustomer() throws Exception
- {
- String type=null;
- Scanner in=new Scanner(System.in);
- double amt=0;
- int acc_id=0;
- int ini_id=10000;
- boolean valid=true;
- System.out.println("Enter the name of holder:");
- String name=in.nextLine();
- System.out.println("Select the account type\n1.saving\n2.current:");
- int a_type=in.nextInt();
- if(a_type==1)
- {
- type="saving";
- System.out.println("Enter initial Balance(minimum balance:1000)");
- amt=in.nextDouble();
- while(amt<1000)
- {
- System.out.println("unacceptable, Enter more than 1000");
- amt=in.nextDouble();
- }
- }
- else if(a_type==2)
- {
- type="current";
- System.out.println("Enter initial Balance(minimum balance:10000)");
- amt=in.nextDouble();
- while(amt<10000)
- {
- System.out.println("unacceptable, Enter more than 10000");
- amt=in.nextDouble();
- }
- }
- else
- {
- System.out.println("Please Retry with valid account type");
- return false;
- }
- System.out.println("Would you like Set your own custom id?");
- System.out.println("1.No,Let Bank assign one for me\n2.Yes,I want Custom Id");
- int temp=in.nextInt();
- if(temp==1)
- {
- while(Account.checkId(ini_id))
- {
- ini_id++;
- }
- acc_id=ini_id;
- }
- else if(temp==2)
- {
- while(true)
- {
- System.out.println("Enter the id you want which should contain only numerics (0-9)");
- int id=in.nextInt();
- try{
- valid=Account.checkId(id);
- }
- catch(Exception e){
- e.printStackTrace();
- }
- if(valid)
- {
- System.out.println("Retry!! Id already Exist");
- }
- else
- {
- acc_id=id;
- break;
- }
- }
- }
- else
- {
- System.out.println("Re-Enter proper details");
- }
- System.out.println("Enter password for your account\n");
- String password=in.next();
- String query1="insert into bank values("+acc_id+",'"+name+"',"+"'"+type+"',"+amt+",1,'"+password+"')";
- Jdbc myjdbc=new Jdbc();
- int st=myjdbc.s.executeUpdate(query1);
- if(st==1)
- {
- System.out.println("Accout Added successfuly");
- try{
- Account.showAccountInfo(acc_id);
- }catch (Exception e) {
- e.printStackTrace();
- }
- }
- else
- {
- System.out.println("Account cannot be added");
- }
- return true;
- }
- }
Add Comment
Please, Sign In to add comment