Database storage ATM machine, account opening, inquiry and other information

Source: Internet
Author: User
Tags stub

Package com.bank.unionpay;//Bank Card Interface public interface I_yinhangka {//abstract method//public abstraction default adornment abstract public abstract void Cxyue ();//check balance void  Cunkuan ();//Deposit void Qukuan ();//withdrawal void accound ();//Account}

  

Package Com.bank.unionpay;import Java.util.arraylist;import Java.util.list;public class Zhujiemian {public void Zhujiemian () {System.out.println ("Bank self-Service terminal system"); System.out.println (); System.out.println ("************************"); List<string> li=new arraylist<> () Li.add ("Account Opening"), Li.add ("Enquiry"), Li.add ("deposit"), Li.add ("withdrawal"), Li.add ("withdrawal"); for (int i=0;i<5;i++) {System.out.println (i+ "------" +li.get (i));} System.out.println (); SYSTEM.OUT.PRINTLN ("Please select the function you want to perform");}}

  

Package Com.bank.unionpay;public Abstract class Atm implements i_yinhangka{string leixing;//bank card type String accound;// Account double qukuan;//withdrawal double cunkuan;//deposit double Cxyue;//balance string name; String sfzheng;//Province Certificate number public Atm (string name,string sfzheng,string accound, double Cxyue) {super (); this.accound = Accound ; This.cxyue = Cxyue;this.name = Name;this.sfzheng = Sfzheng;} Public Atm () {super ();} @Overridepublic void Cxyue () {//check balance Cxyue-=qukuan;cxyue+=cunkuan; System.out.println ("Your balance =" +cxyue);} @Overridepublic void Cunkuan () {//deposit Cxyue+=cunkuan;        System.out.println ("Deposit is successful, your deposit amount is" +cunkuan); System.out.println ("Your balance after this operation is:" +cxyue);} @Overridepublic void Qukuan () {//withdrawal cxyue-=qukuan;if (cxyue>=0) {System.out.println ("withdrawal successful, this withdrawal amount =" +qukuan); System.out.println ("Your balance after this operation =" +cxyue);} ELSE{SYSTEM.OUT.PRINTLN ("Insufficient balance, unable to withdraw money");}} @Overridepublic void Accound () {///Account}//declaration member method Public double Qukuan (double Qukuan)//withdrawal {cxyue-=qukuan;if (cxyue>=0) { System.out.println ("Withdrawal success, this withdrawal amount =" +qukuan); System.out.println ("Your balance after this operation = "+cxyue";} ELSE{SYSTEM.OUT.PRINTLN ("Insufficient balance, unable to withdraw money"); return Qukuan;} Public double Cunkuan (double Cunkuan)//deposit {Cxyue+=cunkuan;        System.out.println ("Deposit is successful, your deposit amount is" +cunkuan); System.out.println ("Your balance after this operation is:" +cxyue); return Cunkuan;} Public double Cxyue (double cxyue) {Cxyue-=qukuan;cxyue+=cunkuan; System.out.println ("Your balance =" +cxyue); return Cxyue;} Add an abstract method for opening an account public abstract void Kaihu ();}

  

Package COM.BANK.UNIONPAY;//Bank Enumeration type public enum leixing {ABC ("AgBank"), ICBC ("ICBC"), CCB ("CCB"), BOC ("BOC");p rivate   Final String Leixing;public string getleixing () {return this.leixing;} Construction method Private leixing (String leixing) {this.leixing=leixing;}}

  

Package Com.bank.abc;import Java.io.serializable;import Java.util.arraylist;import java.util.hashmap;import Java.util.list;import java.util.map;import com.bank.unionpay.leixing;//Simple Interest Mode public class Bank implements Serializable {Private Bank ()//Prohibit external access construction method {}private Static bank  Bank=new Bank ();//Internally generated unique instance public static bank  Getbank ()// Open a method to return this instance to the caller {return bank;} Final leixing lx=leixing.abc;//ABC type private String yhname;//Bank name Public List <string>card=new arraylist<> () ;//bank card list//public map<string, Cxcard > Account=new hashmap<> ();//Account debit card collection}

  

Package Com.bank.abc;import Java.sql.connection;import Java.sql.drivermanager;import java.sql.sqlexception;import Java.sql.statement;import Java.util.random;import Java.util.scanner;import Com.bank.unionpay.atm;import  Com.bank.unionpay.leixing;public class ATM2 extends Atm {public cxcard cx=new cxcard ();//public Atm2 (string name, string Sfzheng, String accound, double Cxyue) {super (name, Sfzheng, Accound, Cxyue);//TODO auto-generated constructor stub}public Atm2 () {//TODO Auto-generated constructor stub super ();} Final leixing lx = leixing.abc; @Overridepublic void Kaihu ()//Implement the account opening {System.out.println ("you select the account opening function"); Scanner sc0=new Scanner (system.in); System.out.println ("Please enter name"); String Name=sc0.nextline (); for (int i=1;i>0;i++) {System.out.println ("Please enter a Social Security number"); String Sfzheng=sc0.nextline (); if (Sfzheng.length () ==18)//determine identity card {for (int j=1;j>0;j++) {System.out.println ("Please enter password" ); String mm= "\\d{6}";//6-digit Regular expression string password=sc0.nextline (); if (password.matches (mm)) {//cx.setpassword (password) ;//write Password random ra=new random ();//randomly generate 6-bit card number int[] CH=new Int[6]; StringBuilder str=new StringBuilder (); String s;//is used to stitch the following for (int k=0;k<6;k++) {ch[k]=ra.nextint (9);//0-9}for (Integer c:ch) {str.append (c.tostring ());// Traverse Stitching 6-bit digital}s=str.tostring ();//cx.setcairnumber (s);//write card number//bank.getbank (). Card.add (Cx.getcairnumber ());// Save the generated debit card number to the bank's bank card list////bank.getbank (). Account.put (Cx.getcairnumber (), CX); Id+ Debit Card Object System.out.println ("successful account Opening"); System.out.println ("Your account is:" +s);//access to the database//1. Load driver: Load the database provided by the driver class try {class.forname ("Oracle.jdbc.driver.OracleDriver") ;} catch (ClassNotFoundException e) {//TODO auto-generated catch block E.printstacktrace ();} 2. Get the database connection connection Conn;try {conn = drivermanager.getconnection ("Jdbc:oracle:thin:@127.0.0.1:1521:orcl", " test0816 "," 123456 "); SYSTEM.OUT.PRINTLN ("Connection successful");//Operation database: Adding and deleting//3. Get the declaration of the Operational database statement st;st = Conn.createstatement (); int y= St.executeupdate ("INSERT into ATM (cairnumber,name,sfzheng,cxyue,password)" + "Values" (' "+s+" ', ' "+name+" ', ' "+sfzheng + "', '" +cx.getcxyue () + "', '" +password+ "')"); catch (SQLException e) {//TODO auto-generated catch Block E.printstacktrace ();} break;} Else{system.out.println ("Please enter 6-digit password");}} break;} ELSE{SYSTEM.OUT.PRINTLN ("Please re-enter your Social Security number");}}}

Package Com.bank.abc;import Java.io.serializable;import Java.sql.connection;import java.sql.drivermanager;import Java.sql.resultset;import Java.sql.sqlexception;import Java.sql.statement;import Java.util.Scanner;import com.bank.unionpay.leixing;//debit card//Only objects of classes that implement the serializable and Externalizable interfaces can be serialized. public class Cxcard implements Serializable {//attribute final leixing lx=leixing.abc;   String name;//name string sfzheng;//ID number string cairnumber2;//card number string password;//password double Cxyue;//Balance//Generate card number get Set method public String Getcairnumber () {return cairNumber2;} public void Setcairnumber (String cairnumber) {this.cairnumber2 = Cairnumber;} Public String GetName () {return name;} public void SetName (String name) {this.name = name;} Public String Getsfzheng () {return sfzheng;} public void Setsfzheng (String sfzheng) {This.sfzheng = Sfzheng;} Public String GetPassword () {return password;} public void SetPassword (String password) {this.password = password;} Public double Getcxyue () {return cxyue;} public void Setcxyue (double Cxyue) {This.cxyue = Cxyue;} Public Cxcard (String cairnumber, string password) {super (); this.cairnumber2 = Cairnumber;this.password = password;} @Overridepublic String toString () {return name: "+ name +" \ n "+" ID: "+ sfzheng +" \ n "+" card number: "+ cairNumber2 +" \ n "+" Balance: " + Cxyue;} Public Cxcard () {//TODO auto-generated constructor stub}//declares member method public void Qukuan ()//withdrawal {if (true) {System.out.println ("you select for withdrawal function"); for ( int i=1;i>0;i++) {Scanner sc1=new Scanner (system.in); System.out.println ("Please enter the card number you want to withdraw"); String c2=sc1.nextline (); try {class.forname ("oracle.jdbc.driver.OracleDriver"); Connection conn = drivermanager.getconnection ("Jdbc:oracle:thin:@127.0.0.1:1521:orcl", "test0816", "123456"); Statement st = Conn.createstatement ();//Query The result set of the user input card number resultset rs =st.executequery ("select * from ATM where cairnumber = ') "+c2 +" "); if (Rs.next ()) {String SS = rs.getstring (" password "); for (int k = 0; k<3; k++) {System.out.println ("Please enter your password:"); Scanner mm = new Scanner (system.in); String Mima = Mm.nextline (); if (Ss.equals (Mima)) {System.out.println ("Please enter the withdrawal amount"); Scanner SC =new Scanner (system.in);d ouble qk =sc.nextdouble (); if (qk>0) {Double Yue = rs.getdouble ("Cxyue"); if (qk< =yue) {double Sumyue =yue-qk;st.executeupdate ("Update ATM set cxyue= '" +sumyue+ "' where cairnumber ' +" = ' "+c2 +" ' "); System.out.println ("successful withdrawal"); Else{system.out.println ("Your balance is insufficient to withdraw money");}} ELSE{SYSTEM.OUT.PRINTLN ("The amount of withdrawal you entered is not recognized by the system");}} ELSE{SYSTEM.OUT.PRINTLN ("Incorrect password");} break;} break;} Rs.close (); St.close (); Conn.close ();} catch (ClassNotFoundException | SQLException e) {//TODO auto-generated catch block E.printstacktrace ();}}} public void Cunkuan ()//Deposit {if (true) {System.out.println ("you choose to deposit function"); for (int i=1;i>0;i++) {Scanner sc1=new Scanner ( system.in); System.out.println ("Please enter the card number you want to deposit"); String c2=sc1.nextline (); try {class.forname ("oracle.jdbc.driver.OracleDriver"); Connection conn = drivermanager.getconnection ("Jdbc:oracle:thin:@127.0.0.1:1521:orcl", "test0816", "123456"); Statement st = Conn.createstatement ();//Query The result set of the user input card number resultset rs =st.executequery ("Select* from ATM where cairnumber = ' "+c2 +" ' "), if (Rs.next ()) {String SS = rs.getstring (" password "); for (int k = 0; k<3; k++) {System.out.println ("Please enter your password:"); Scanner mm = new Scanner (system.in); String Mima = Mm.nextline (), if (Ss.equals (Mima)) {System.out.println ("Please enter deposit amount"); Scanner SC =new Scanner (system.in);d ouble ck =sc.nextdouble (); if (ck>=0) {Double Yue = rs.getdouble ("Cxyue");d ouble Sumyue =yue+ck;st.executeupdate ("Update ATM set cxyue= '" +sumyue+ "' where cairnumber" + "= '" +c2 + "'"); System.out.println ("deposit success"); ELSE{SYSTEM.OUT.PRINTLN ("You entered the deposit amount, the system does not recognize");}} ELSE{SYSTEM.OUT.PRINTLN ("Incorrect password");} break;} break;} Rs.close (); St.close (); Conn.close ();} catch (ClassNotFoundException | SQLException e) {//TODO auto-generated catch block E.printstacktrace ();}}} public void Cxyue ()//query {if (true) {System.out.println ("The Query function you select"); for (int i=1;i>0;i++) {Scanner sc1=new Scanner ( system.in); System.out.println ("Please enter the card number you want to inquire"); String c2=sc1.nextline (); try {class.forname ("oracle.jdbc.driver.OracleDriver"); Connection Conn = drivermanager.getconnection ("Jdbc:oracle:thin:@127.0.0.1:1521:orcl", "test0816", "123456"); Statement st = Conn.createstatement (); ResultSet rs =st.executequery ("select * from ATM where cairnumber = '" +c2 + "'"); if (Rs.next ()) {String SS = rs.getstring ( "Password"); for (int k = 0; k<3; k++) {System.out.println ("Please enter your password:"); Scanner mm = new Scanner (system.in); String Mima = Mm.nextline (), if (Ss.equals (Mima)) {System.out.println ("Your information is:"); System.out.println ("Name:" +rs.getstring ("name") + "\ T ID number:" +rs.getstring ("Sfzheng") + "\ T account:" +rs.getstring (" Cairnumber ") +" \ t balance "+rs.getstring (" Cxyue "); ELSE{SYSTEM.OUT.PRINTLN ("Incorrect password");} break;} break;} Rs.close (); St.close (); Conn.close ();} catch (ClassNotFoundException | SQLException e) {//TODO auto-generated catch block E.printstacktrace ();}}}}

Package Com.bank.test;import Java.io.file;import Java.io.fileinputstream;import java.io.fileoutputstream;import Java.io.objectinputstream;import Java.io.objectoutputstream;import Java.sql.connection;import Java.sql.drivermanager;import Java.sql.statement;import Java.util.hashmap;import Java.util.Map;import Java.util.scanner;import Com.bank.abc.atm2;import Com.bank.abc.bank;import Com.bank.abc.cxcard;import Com.bank.unionpay.atm;import Com.bank.unionpay.leixing;import Com.bank.unionpay.zhujiemian;public class A {public static void Main (string[] args) throws exception{for (int i=1;i>0;i++) {Zhujiemian zjm=new Zhujiemian (); Zjm.zhujiemian (); Scanner sc=new Scanner (system.in); int in=sc.nextint (); if (in==0| | in==1| | in==2| | in==3| | in==4) {if (in==0) {//Test account opening Atm2 a2=new Atm2 (); A2.kaihu (); continue;} Query if (in==1) {Atm2 a2=new Atm2 (); A2.cx.cxyue (); continue;} if (in==2) {//Deposit ATM2 a2=new Atm2 (); A2.cx.cunkuan (); continue;} if (in==3) {//Withdrawals Atm2 a2=new Atm2 (); A2.cx.qukuan (); continue;} if (in==4) {//Exit System.out.priNTLN ("System is about to exit"),//file fi=new File ("d:/abc122");//if (!fi.exists ())//{//fi.mkdirs ();//}//objectoutputstream obj=new ObjectOutputStream (New FileOutputStream ("D:/abc122/abc.obj"));//obj.writeobject (Bank.getbank (). account);// SYSTEM.OUT.PRINTLN ("Data Save Complete");//obj.close ();//break;}} Else{system.out.println ("The menu does not exist");}}}

  

Database storage ATM machine, account opening, inquiry and other information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.