Java object-oriented practice---Bank business Simulation (array + object-oriented)

Source: Internet
Author: User

  • Programming Implementation:
    A) User class: Account number (int), name (string), password (int:6 digit), address (string), deposit balance (double), registration time (date), opening bank (corresponding to the name of the banks, String)
    b) Address class: Country (String), Province (String), Street (string), house number (string)
    C) Bank class: A library that can store 100 users ([]), the bank name (e.g., the Changping sub-branch of ICBC, String)
    I. Banking functions
  • Add user (incoming parameter: User, return value: Integer value (1: Success, 2: User already exists, 3: User library is full))
    A) Business logic: first check if the user's account exists in the library. If it does not exist, add a user in the user's library and return the Code 1, and return the code 2 if it exists. In addition, when adding users to detect whether the user library is full, if full, return code 3
  • Save money (incoming value: The user's account number, the amount of access.) Return value: Boolean type value)
    A) business logic: First, based on the incoming account information to find out whether the user in the user's library. If not, returns False if any, and then saves the user's amount in.
  • Withdraw Money (incoming value: User's account number, user password, withdraw money amount. Return value: Integer value (0: Normal, 1: account does not exist, 2: Wrong password, 3: Insufficient money))
    A) business logic: First, according to the account information to query whether the user exists, if not, then return code 1, if present, continue to determine whether the password is correct, if not correct, then return code 2. If the account password is correct, then continue to determine whether the current user's amount is satisfied to withdraw the money, if not satisfied, the return code 3, if satisfied, then the amount of the user minus.
  • Transfer (incoming value: The transferred account, the account transferred, the password to be transferred out of the account, the amount transferred out. Return value: 0: Normal, 1: Wrong account, 2 wrong password, 3 not enough money)
    A) business logic: First query the user base for the presence of the transfer and transfer of the account, if not there is the return code, 1, if the account is present to continue to determine whether the password is correct, if not correct, then return 2, if correct, continue to determine whether the amount to be transferred is sufficient, if not enough then return 3, otherwise, The amount of the transferred account should be reduced correspondingly, and the amount transferred will be increased correspondingly.
  • Query account function (incoming value: Account number, account password, return value: null)
    A) business logic: First, according to the account to determine whether the user library exists the user, if not exist, print the prompt message: it does not exist. Otherwise, continue to determine if the password is correct. If it is not correct, the corresponding error message is printed. If the account and password are correct, then the user's information will be printed out, such as: Current account: xxxx, password: xxxxxx, balance: xxxx Yuan, the user live address: xxxxxxxxxxxxx, the current account of the bank: Xxxxxxxxxx.
    D) Interface class: When the entry is executed, the Bank Business selection menu is printed: for example:
    I.
    II. Then start processing various input operations until the business process is complete!
  • Answer:
    1. Address class

    Class address{
    Private String country;//Country
    Private String province;//Province
    Private String street;//Street
    Private String id;//Gate automatic arranging

    public Address(){}public Address(String country,String province,String street,String id){    this.country = country;    this.province = province;    this.street = street;    this.id = id;}public void setCountry(String country){    this.country = country;}public String getCountry(){    return this.country;}public void setProvince(String province){    this.province = province;}public String getProvince(){    return this.province;}public void setStreet(String street){    this.street = street;}public String getStreet(){    return this.street;}public void setId(String id){    this.id = id;}public String getId(){    return this.id;}

    }

    2、用户类

    Class user{
    private int code;//Account
    Private String name;//Name
    private int password;//Password
    Private address address;//addresses
    Private double money;//deposit balance
    Private Date date;//Registration time
    Private String openbankname;//Bank

    Public user () {}public user (int code,string name,int password,address address,double money,date date,string openBankName    {this.code = code;    THIS.name = name;    This.password = password;    this.address = address;    This.money = money;    This.date = date; This.openbankname = Openbankname;} public void Setcode (int code) {this.code = code;} public int GetCode () {return this.code;} public void SetName (String name) {this.name = name;} Public String GetName () {return this.name;} public void SetPassword (int password) {this.password = password;} public int GetPassword () {return this.password;} public void setaddress (address address) {this.address = address;} Public Address getaddress () {return this.address;} public void Setmoney (double money) {This.money = money;} Public double Getmoney () {return this.money;} public void SetDate (date date) {this.date = date;} Public Date GetDate () {return this.date;} public void Setopenbankname (String openbankname) {this.Openbankname = Openbankname;} Public String Getopenbankname () {return this.openbankname;}

    }

    3. Bank class

    Class bank{
    Private String Bankname;

    Static user[] users = new USER[10];p Ublic Bank () {}public Bank (String bankname) {this.bankname = Bankname;} public void Setbankname (String bankname) {this.bankname = Bankname;} Public String Getbankname () {return this.bankname;} /** checks if the user exists */public boolean checkUser (int code) {for (user u:users) {if (U! = null) {if (u.getc            Ode () = = code) {return true; }}} return false;} /** Check whether the user is full */public boolean isfulluser () {for (user user:users) {if (user = = null) {return fals        E }} return true; /** check that the user and password are correct */public boolean checkuserandpassword (int usercode, int password) {if (CheckUser (Usercode)) {F                    or (User u:users) {if (u.getcode () = = Usercode) {if (U.getpassword () = = password) {                return true; }}}} return false;} /** Check if money is enough */public boolean checkmoney (int usercode,double) {foR (User u:users) {if (u.getcode () = = Usercode) {if (U.getmoney () >= money) {return T            Rue            }else{break; }}} return false;}     /** Add user's method */public int addUser (user user) {if (CheckUser (User.getcode ())) {return 2;    }else if (Isfulluser ()) {return 3;                 }else{for (int i = 0;i < Users.length; i++) {if (users[i] = = null) {Users[i] = user; return 1;

    //break;
    }
    }
    }
    return 1;
    }

    /** Save Method */public boolean Savemoney (int usercode,double money) {if (!checkuser (Usercode)) {return false; }else{for (User u:users) {if (u.getcode () = = Usercode) {U.setmoney (U.getmoney () + Mone            y); }}} return true;  /** take Money method */public int Takemoney (int usercode,int password,double Takemoney) {if (!checkuser (Usercode)) {return    1;    }else if (!checkuserandpassword (Usercode,password)) {return 2;    }else if (!checkmoney (Usercode,takemoney)) {return 3; }else{for (User u:users) {if (u.getcode () = = Usercode) {U.setmoney (U.getmoney ()-Take                Money);            Break }}} return 0;} /** transfer Method */public int TransferMoney (int outcode,int incode,int outpassword,double Outmoney) {if (!checkuser (OutCode)    && CheckUser (Incode)) {return 1;    }else if (!checkuserandpassword (Outcode,outpassword)) {return 2; }else if (!checkmoney (Outcode,outmoney)) {return 3;        }else{Savemoney (Incode,outmoney);    Takemoney (Outcode,outpassword,outmoney); } return 0;} /** query account */public void selectuser (int usercode,int password) {if (!checkuser (Usercode)) {System.out.println ("the User does not exist! ");}    else if (!checkuserandpassword (Usercode,password)) {System.out.println ("password wrong!");        }else{User u = null;        Address address = null;                for (user user:users) {if (user.getcode () = = Usercode) {u = User;                Address = u.getaddress ();            Break  }} System.out.println ("Current account is: \ t" + u.getname () + "\ n Account:" + usercode + "\ n Password:" + password + "\ n Balance:" + u.getmoney () + "\ n User's current residence address: \ t" + address.getcountry () + address.getprovince () + "city" +    Address.getstreet () + address.getid () + "number!"); }}

    }

    4. Page Emulation class

    Class page{
    public static void Welcomepage () {
    SYSTEM.OUT.PRINTLN ("* *");
    System.out.println (" ICBC ");
    System.out.println (" Account Management System ");
    System.out.println (" V1.0 ");
    SYSTEM.OUT.PRINTLN ("* *");
    System.out.println (" 1. Account opening ");
    System.out.println (" 2. Saving money ");
    System.out.println (" 3. Withdraw Money ");
    System.out.println (" 4. Transfer ");
    System.out.println (" 5. Enquiry ");
    System.out.println (" 6.bye! ");
    SYSTEM.OUT.PRINTLN ("* *");
    }
    }

    5, the specific test class
    import java.util.Date;
    Import Java.util.Scanner;
    public class demo{
    private static Scanner sc = new Scanner (system.in);
    private static Bank Bank = new Bank ("ICBC Shahe sub-branch");
    public static void Main (string[] args) {
    Page.welcomepage ();
    System.out.print ("Please enter the Business number:");
    int num = Sc.nextint ();
    if (num = = 1) {
    System.out.print ("Please enter account number:");
    int code = Sc.nextint ();
    System.out.print ("\ n Please enter user name:");
    String name = Sc.next ();
    System.out.print ("\ n Please enter password:");
    int password = sc.nextint ();
    System.out.print ("\ n Please enter the address to enter the residence, first enter the country:");
    String country = Sc.next ();
    System.out.print ("\ n Please enter province:");
    String province = Sc.next ();
    System.out.print ("\ n Please enter street:");
    String Street = Sc.next ();
    System.out.print ("\ n Please enter house number:");
    String id = sc.next ();
    System.out.print ("\ n Please enter your account's initial balance:");
    Double money = sc.nextdouble ();

            Address address = new Address(country,province,street,id);        User user = new User(code,name,password,address,money,new Date(),bank.getBankName());        int n = bank.addUser(user);        if (n == 2){            System.out.println("对不起,您输入的账户已存在,无法开户,请带好证件到营业厅窗口办理!");        }else if (n == 3){            System.out.println("对不起,当前银行的用户数已满,请到其他银行办理业务!");        }else if (n == 1){            System.out.println("恭喜你,开户成功下面是您的开户信息:");            bank.selectUser(code,password);        }    }else if (num == 2){    }else if (num == 3){    }else if (num == 4){    }else if (num == 5){    }else if (num == 6){        System.out.println("Bye~~");        System.exit(0);    }}

    }

    Java object-oriented practice---Bank business Simulation (array + object-oriented)

    Related Article

    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.