栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java函数实现ATM机系统

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java函数实现ATM机系统

  • ATM.java

import java.util.Arrays;
import java.util.Scanner;

public class ATM {
    static Account account = new Account();
    static Bank bank = new Bank();
    public static void main(String[] args) {

        int i,type;
        Login(account.getAccountId(),account.getPassword(),account.getBalance(),account.getType());


    }
    public static void Login(String accountId[],int password[],double balance[],int type[]){
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入账号:");
        String user = scanner.next();
        for (int i=0;i 
  • Bank.java
import java.util.Scanner;

public class Bank {
    private static String accountId;
    private static int type;
    private static int password;
    private static double balance;
    public void Account(int i,String accountId[],int password[],double balance[],int type[]){
        this.accountId = accountId[i];
        this.password = password[i];
        this.balance = balance[i];
        this.type = type[i];
    }


    public static String[] Logout(String accountId[]){
        Scanner scanner = new Scanner(System.in);
        String user = " ";
        String error = " ";
        System.out.println("请输入要注销的用户");
        user = scanner.next();
        System.out.println("确定删除吗 yes no");
        error = scanner.next();
        if (error.equals("yes")){
            for (int i = 0; i < accountId.length; i++) {
                if (accountId[i].equals(user)){
                    accountId[i] = "已注销";
                    System.out.println("注销成功!");
                    return accountId;
                }

            }
            System.out.println("未找到该用户!");
            Logout(accountId);
        }else{
            System.out.println("取消成功!!");
        }
        return accountId;
    }




    public static void List(String accountId[],int password[],double balance[],int type[]) {
        String type_new = " ";
        for (int i = 0; i < balance.length; i++) {
            if (type[i] == 0){
                type_new = "普通用户";
            }else{
                type_new = "管理员用户";
            }
            if (!accountId[i].equals("已注销")){
                System.out.println("用户名:"+accountId[i]+' '+"密码:"+password[i]+' '+"账户余额:"+balance[i]+' '+type_new);
            }

        }
    }

    public static String[] add_user(String accountId[]){
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入新用户账号!");
        String new_name = scanner.next();
        String[] newarr_user = new String[accountId.length+1];
        for (int j = 0; j <= accountId.length-1; j++) {
            newarr_user[j]  =  accountId[j];
        }
        newarr_user[accountId.length]  =  new_name;
        accountId = newarr_user;
        return accountId;
    }
    public static int[] add_pass(int password[]){
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入新用户密码!");
        int new_pass = scanner.nextInt();
        int[] newarr_pass = new int[password.length+1];
        for (int j = 0; j <= password.length-1; j++) {
            newarr_pass[j]  =  password[j];
        }
        newarr_pass[password.length]  =  new_pass;
        password = newarr_pass;
        return password;
    }
    public static double[] add_balance(double balance[]){
        Scanner scanner = new Scanner(System.in);
        double[] newarr_balance = new double[balance.length+1];
        for (int j = 0; j <= balance.length-1; j++) {
            newarr_balance[j] =  balance[j];
        }
        newarr_balance[balance.length] =  0;
        balance = newarr_balance;
        return balance;
    }
    public static int[] add_type(int type[]){
        Scanner scanner = new Scanner(System.in);
        int[] newarr_type = new int[type.length+1];
        for (int j = 0; j <= type.length-1; j++) {
            newarr_type[j] =  type[j];
        }
        newarr_type[type.length] =  0;
        type = newarr_type;
        return type;
    }

    public static int verify(String str){
        int new_int = 0;
        try{
            new_int =Integer.parseInt(str);
        }catch (NumberFormatException e){
            return -1;
        }
        return new_int;
    }
    public static int edit_pass() {
        Scanner scanner = new Scanner(System.in);
        String new_pass = " ";
        int pass = 0;
        System.out.println("输入原密码!");
        new_pass = scanner.next();
        pass = verify(new_pass);
        if(pass != -1){
            if (pass == password){
                while(true){
                    System.out.println("请输入新密码!!");
                    new_pass = scanner.next();
                    pass = verify(new_pass);//验证输入是否为数字
                    if (pass != -1){
                        password = pass;
                        return password;
                    }
                    System.out.print("请输入数字,重新");
                }

            }
        }else{
            System.out.print("请输入数字,重新");
            edit_pass();
            return password;
        }
        System.out.print("密码错误!重新");
        edit_pass();
        return 0;
    }

    public static double  withdraw(){//取款
        Scanner scanner = new Scanner(System.in);
        double edit_balance=0;
        System.out.println("请输入取款数目");
        edit_balance = scanner.nextDouble();
        if (edit_balance > balance){
            System.out.println("您的余额不足,请重新输入");
            withdraw();
        }
        balance =  balance - edit_balance;
        return balance;
    }
    public static double deposit(){//存款
        Scanner scanner = new Scanner(System.in);
        double edit_balance=0;
        System.out.println("请输入存款数额");
        edit_balance = scanner.nextDouble();
        balance = balance + edit_balance;
        return balance;
    }
    public static void inquiry(){//查询
        System.out.println("账户余额:"+balance);
    }
    public static double[] transfer(int i,String new_accountId[],double new_balance[]){
        double re_money[];
        Scanner scanner = new Scanner(System.in);
        double edit_balance=0;
        System.out.println("请输入转账数目");
        edit_balance = scanner.nextDouble();
        if (edit_balance > new_balance[i]){
            System.out.println("您的余额不足,请重新输入");
            transfer(i,new_accountId,new_balance);
            return new_balance;
        }
        new_balance[i] = new_balance[i] - edit_balance;
        while(true){
            System.out.println("请输入转账账号:");
            String user = scanner.next();
            for (int j = 0; j < new_accountId.length; j++) {
                if (new_accountId[j].equals(user)){
                    new_balance[j] += edit_balance;
                    System.out.println("转账成功!!");
                    return new_balance;
                }
            }
        }
    }
}

  • Account.java
import java.util.Scanner;

public class Account {
    private static String accountId[] = {"admin", "w001", "w002", "w003"};
    private static int type[] = {1,0,0,0};
    private static int password[] = {123,456,789,111};
    private static double balance[] = {100.0,200.0,300.0,0};
    public String[] getAccountId() {
        return accountId;
    }

    public void setAccountId(String[] accountId) {
        this.accountId = accountId;
    }
    public int[] getType() {
        return type;
    }

    public void setType(int[] type) {
        this.type = type;
    }

    public int[] getPassword() {
        return password;
    }

    public void setPassword(int[] password) {
        this.password = password;
    }

    public double[] getBalance() {
        return balance;
    }

    public void setBalance(double[] balance) {
        this.balance = balance;
    }
    public void user_accountId(int i,String New_Id){
        accountId[i] = New_Id;
    }
    public void user_password(int i,int New_pass){
        password[i] = New_pass;
    }
    public void user_Balance(int i,double New_Balance){
        balance[i] = New_Balance;
    }
    public void user_type(int i,int New_type){
        type[i] = New_type;
    }
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/666424.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号