“修仙版“ATM系统

news/2024/10/20 20:53:31/

"修仙版"ATM指南

    • 一、问题描述
    • 二、基本流程
    • 三、具体步骤
      • 1.定义属性类
      • 2.菜单栏
      • 3.账户注册
        • (1)根据ID获取账户
        • (2)获取注册ID
        • (3)注册账户
      • 4.账户登录
      • 5.登录界面
      • 6.操作界面
        • (1)查询
        • (2)交易界面
          • (1)存款
          • (2)取款
          • (3)转账
            • (a)得到屏蔽姓名
            • (b)转账
          • (4)退出交易
        • (3)退出登录
        • (4)注销账户
    • 四、代码实现
    • 五、效果展示
      • 1.账户注册
      • 2.账户登录
        • (1)查询属性
        • (2)交易界面
          • (1)存款
          • (2)取款
          • (3)转账
          • (4)退出交易系统
        • (3)退出登录
        • (4)注销账户
        • (5)登录【萧炎】的账户

一、问题描述

烛九幽穿越到了九州修仙界,加入了人族第一大势力:仙盟,他发现宗门的任务系统有点眼熟,就是披着仙侠皮的ATM系统。下面我们就来实现仙侠版的ATM系统。

二、基本流程

定义property类
注册账户
账户登录

三、具体步骤

1.定义属性类

/*** 定义属性类*/
class property{private String name;//姓名private String ID;//身份号private String password;//密码private int age;//年龄private String race;//种族private String quality;//修为private int contribution;//贡献点public property(String name, String ID, String password, int age, String race, String quality, int contribution) {this.name = name;this.ID = ID;this.password = password;this.age = age;this.race = race;this.quality = quality;this.contribution = contribution;}public property() {}public String getQuality() {return quality;}public void setQuality(String quality) {this.quality = quality;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getID() {return ID;}public void setID(String ID) {this.ID = ID;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}public String getRace() {return race;}public void setRace(String race) {this.race = race;}public int getContribution() {return contribution;}public void setContribution(int contribution) {this.contribution = contribution;}
}

2.菜单栏

private static void menu() {System.out.println("-----------------欢迎道友来到仙盟---------------------");System.out.println("请您选择操作:");System.out.println("1.注册账户");System.out.println("2.登录系统");System.out.println("3.退出");}

3.账户注册

(1)根据ID获取账户

    /*** 通过ID获得账户信息** @param proArrayList 集合* @param ID* @return 找到的账户信息(如果未找到,返回null)*/private static property getproByID(ArrayList<property> proArrayList, String ID) {for (int i = 0; i < proArrayList.size(); i++) {if(ID.equals(proArrayList.get(i).getID()))return proArrayList.get(i);}return null;}

(2)获取注册ID

   /*** 获取不重复的ID* @return ID*/private static String getPropertyID(ArrayList<property> proArrayList) {Random ran = new Random();while(true){StringBuilder sb=new StringBuilder();for (int i = 0; i < 9; i++) {sb.append(ran.nextInt(10));}String ID = sb.toString();property pro = getproByID(proArrayList,ID);if(pro==null)return ID;}}

(3)注册账户

   /*** 进入注册/登录界面* @param sca 扫描器* @param proArrayList 集合*/private static void register(Scanner sca, ArrayList<property> proArrayList) {System.out.println("-----------------注册---------------------");property pro = new property();System.out.println("请您输入您的姓名:");String name = sca.next();pro.setName(name);System.out.println("请输入您的年龄:");int age = sca.nextInt();pro.setAge(age);System.out.println("请您输入您的种族:");String race = sca.next();pro.setRace(race);System.out.println("请您输入您的修为:");String quality = sca.next();pro.setQuality(quality);String ID;ID = getPropertyID(proArrayList);pro.setID(ID);System.out.println("请您输入登录密码:");String password = sca.next();pro.setPassword(password);System.out.println("尊敬的【"+name+"】道友,您的登录ID是:"+ID);proArrayList.add(pro);//添加到集合中}

4.账户登录

    /*** 登录系统* @param sca 扫描器* @param proArrayList 集合*/private static void longin(Scanner sca, ArrayList<property> proArrayList) {while (true){System.out.println("请您输入您的登录ID:");String ID = sca.next();property pro = getproByID(proArrayList,ID);if(pro == null){System.out.println("系统中未查询到该用户,请您检查ID输入是否正确,请重新输入!");}else{while (true){System.out.println("请您输入登录密码:");String password = sca.next();if(pro.getPassword().equals(password)){System.out.println("密码输入正确!");System.out.println("登录成功!");users_function(sca,pro,proArrayList);break;//登录成功,退出内循环}else {System.out.println("密码输入错误,请您重新输入!");}}}break;}}

5.登录界面

    /*** 用户操作具体实现* @param sca 扫描器* @param pro 登录的账户* @param proArrayList 集合*/private static void users_function(Scanner sca, property pro, ArrayList<property> proArrayList) {boolean flag = false;boolean flag2 = false;while (true) {function();System.out.println("请您输入选择的操作命令:");int input = sca.nextInt();switch (input) {case 1://查询check_property(pro);break;case 2://交易deal_property(sca,pro,proArrayList);break;case 3://退出flag = quit_porperty();break;case 4://注销flag2 = logout_porperty(sca,pro,proArrayList);break;}if (flag||flag2)break;}}

6.操作界面

    /*** 用户操作界面*/private static void function() {System.out.println("------------欢迎来到用户操作界面------------");System.out.println("请您输入选择:");System.out.println("1.查询");System.out.println("2.交易");System.out.println("3.退出");System.out.println("4.注销");}

(1)查询

    /*** 展示属性* @param pro 登录的该账户*/private static void check_property(property pro) {System.out.println("----------------------属性------------------------");System.out.print("【");System.out.println("姓名:"+pro.getName());System.out.println("ID:"+pro.getID());System.out.println("年龄:"+pro.getAge());System.out.println("修为:"+pro.getQuality());System.out.println("种族:"+pro.getRace());System.out.print("贡献点:"+pro.getContribution());System.out.println("】");}

(2)交易界面

    /*** 交易系统* @param sca 扫描器* @param pro 登录的账户* @param proArrayList 集合*/private static void deal_property(Scanner sca, property pro, ArrayList<property> proArrayList) {boolean flag = false;while(true){System.out.println("-------------------交易系统---------------------");System.out.println("1.存款");System.out.println("2.取款");System.out.println("3.转账");System.out.println("4.退出");System.out.println("请您输入您的选择:");int input = sca.nextInt();switch (input){case 1://存款add_contribution(sca,pro);break;case 2://取款sub_contribution(sca,pro);break;case 3://转账transfer_contribution(sca,pro,proArrayList);break;case 4://退出flag = quit_deal();break;}if(flag)break;}}
(1)存款
    /*** 存款* @param sca 扫描器* @param pro 登录的账户*/private static void add_contribution(Scanner sca, property pro) {System.out.println("-----------------存款----------------------");System.out.println("请您输入待存的贡献点数:");int contr = sca.nextInt();pro.setContribution(pro.getContribution()+contr);System.out.println("您已成功存取 "+contr+" 点贡献点!");System.out.println("您当前共有贡献点:"+pro.getContribution());}
(2)取款
    /*** 取出贡献点* @param sca 扫描器* @param pro 登录的账户*/private static void sub_contribution(Scanner sca, property pro) {System.out.println("---------------------取款----------------------");while (true){System.out.println("请您输入待取点数:");int contr = sca.nextInt();if(contr>=0){if(contr<=pro.getContribution()) {pro.setContribution(pro.getContribution()-contr);System.out.println("您已成功取出"+contr+"点!");System.out.println("您当前共有贡献点:"+pro.getContribution());break;}System.out.println("您的余额不足!");System.out.println("当前余额为:"+pro.getContribution());System.out.println("请您重新输入!");}else{System.out.println("您输入的点数非法,请您重新输入!");}}}
(3)转账
(a)得到屏蔽姓名
    /*** 得到屏蔽姓名* @param other_pro 对方账户* @return 屏蔽姓名*/private static String getotherName(property other_pro) {String name = other_pro.getName();int flag = name.length();String other_name ="";if(flag==2)return other_name = name.replace(name.substring(1),"*");if(flag==3)return other_name=name.replace(name.substring(1),"**");else return other_name=name.replace(name.substring(2),"**");}
(b)转账
    /*** 转账* @param sca 扫描器* @param pro 登录的账户* @param proArrayList 集合*/private static void transfer_contribution(Scanner sca, property pro, ArrayList<property> proArrayList) {System.out.println("--------------------转账-----------------------");if(proArrayList.size()<2){System.out.println("当前系统中只有一个账户,无法转账!");return;}while (true){System.out.println("请您输入对方账户的ID:");String other_ID = sca.next();if(other_ID.equals(pro.getID()))System.out.println("您输入的是自己的ID,无法转账,请您重新输入!");property other_pro = new property();other_pro = getproByID(proArrayList,other_ID);if(other_pro==null){System.out.println("系统中查无此人,请您重新输入!");}else{while (true){System.out.println("请您输入要转账的贡献点数:");int contr = sca.nextInt();if(contr>=0){if(contr<=pro.getContribution()){while(true){String other_name = getotherName(other_pro);System.out.println("请您输入【"+other_name+"】的完整姓名以验证身份!");String input_name = sca.next();if(other_pro.getName().equals(input_name)){other_pro.setContribution(other_pro.getContribution()+contr);pro.setContribution(pro.getContribution()-contr);System.out.println("您已成功转账 "+contr+" 点贡献点!");System.out.println("您当前还有 "+pro.getContribution()+" 点贡献点!");break;}else{System.out.println("您输入的姓名有误,请您重新输入!");}}break;}else{System.out.println("您当前贡献点不足!");System.out.println("当前您的贡献点为:"+pro.getContribution());System.out.println("请您重新输入!");}}else {System.out.println("您输入的点数非法,请您重新输入!");}}}break;}}
(4)退出交易
    /*** 退出交易* @return true*/private static boolean quit_deal() {System.out.println("------------------退出交易------------------");System.out.println("您已退出交易系统!");return true;}

(3)退出登录

    /*** 退出登录*/private static boolean quit_porperty() {System.out.println("-------------------退出登录--------------------");System.out.println("您已退出登录!");return true;}

(4)注销账户

    /*** 注销账户* @param sca 扫描器* @param pro 登录的账户* @param proArrayList 集合* @return true*/private static boolean logout_porperty(Scanner sca, property pro, ArrayList<property> proArrayList) {System.out.println("----------------注销账户-------------------");System.out.println("请您确认是否要注销账户? 是/否");System.out.println("请你输入选择:");String input = sca.next();if(input.equals("是")){proArrayList.remove(pro);System.out.println("注销账户成功!");return true;}elsereturn false;}

四、代码实现

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;public class tianwang {public static void main(String[] args) {Scanner sca = new Scanner(System.in);ArrayList<property> proArrayList = new ArrayList<>();while (true){menu();while(true){System.out.println("请您输入选择命令:");int input = sca.nextInt();switch(input){case 1:register(sca,proArrayList);break;case 2:longin(sca,proArrayList);break;case 3:System.out.println("仙盟感谢道友的光临!");return;default:System.out.println("输入错误,请您重新输入!");}break;}}}/*** 登录系统* @param sca 扫描器* @param proArrayList 集合*/private static void longin(Scanner sca, ArrayList<property> proArrayList) {while (true){System.out.println("请您输入您的登录ID:");String ID = sca.next();property pro = getproByID(proArrayList,ID);if(pro == null){System.out.println("系统中未查询到该用户,请您检查ID输入是否正确,请重新输入!");}else{while (true){System.out.println("请您输入登录密码:");String password = sca.next();if(pro.getPassword().equals(password)){System.out.println("密码输入正确!");System.out.println("登录成功!");users_function(sca,pro,proArrayList);break;//登录成功,退出内循环}else {System.out.println("密码输入错误,请您重新输入!");}}}break;}}/*** 用户操作具体实现* @param sca 扫描器* @param pro 登录的账户* @param proArrayList 集合*/private static void users_function(Scanner sca, property pro, ArrayList<property> proArrayList) {boolean flag = false;boolean flag2 = false;while (true) {function();System.out.println("请您输入选择的操作命令:");int input = sca.nextInt();switch (input) {case 1://查询check_property(pro);break;case 2://交易deal_property(sca,pro,proArrayList);break;case 3://退出flag = quit_porperty();break;case 4://注销flag2 = logout_porperty(sca,pro,proArrayList);break;}if (flag||flag2)break;}}/*** 注销账户* @param sca 扫描器* @param pro 登录的账户* @param proArrayList 集合* @return true*/private static boolean logout_porperty(Scanner sca, property pro, ArrayList<property> proArrayList) {System.out.println("----------------注销账户-------------------");System.out.println("请您确认是否要注销账户? 是/否");System.out.println("请你输入选择:");String input = sca.next();if(input.equals("是")){proArrayList.remove(pro);System.out.println("注销账户成功!");return true;}elsereturn false;}/*** 交易系统* @param sca 扫描器* @param pro 登录的账户* @param proArrayList 集合*/private static void deal_property(Scanner sca, property pro, ArrayList<property> proArrayList) {boolean flag = false;while(true){System.out.println("-------------------交易系统---------------------");System.out.println("1.存款");System.out.println("2.取款");System.out.println("3.转账");System.out.println("4.退出");System.out.println("请您输入您的选择:");int input = sca.nextInt();switch (input){case 1://存款add_contribution(sca,pro);break;case 2://取款sub_contribution(sca,pro);break;case 3://转账transfer_contribution(sca,pro,proArrayList);break;case 4://退出flag = quit_deal();break;}if(flag)break;}}/*** 退出交易* @return true*/private static boolean quit_deal() {System.out.println("------------------退出交易------------------");System.out.println("您已退出交易系统!");return true;}/*** 转账* @param sca 扫描器* @param pro 登录的账户* @param proArrayList 集合*/private static void transfer_contribution(Scanner sca, property pro, ArrayList<property> proArrayList) {System.out.println("--------------------转账-----------------------");if(proArrayList.size()<2){System.out.println("当前系统中只有一个账户,无法转账!");return;}while (true){System.out.println("请您输入对方账户的ID:");String other_ID = sca.next();if(other_ID.equals(pro.getID()))System.out.println("您输入的是自己的ID,无法转账,请您重新输入!");property other_pro = new property();other_pro = getproByID(proArrayList,other_ID);if(other_pro==null){System.out.println("系统中查无此人,请您重新输入!");}else{while (true){System.out.println("请您输入要转账的贡献点数:");int contr = sca.nextInt();if(contr>=0){if(contr<=pro.getContribution()){while(true){String other_name = getotherName(other_pro);System.out.println("请您输入【"+other_name+"】的完整姓名以验证身份!");String input_name = sca.next();if(other_pro.getName().equals(input_name)){other_pro.setContribution(other_pro.getContribution()+contr);pro.setContribution(pro.getContribution()-contr);System.out.println("您已成功转账 "+contr+" 点贡献点!");System.out.println("您当前还有 "+pro.getContribution()+" 点贡献点!");break;}else{System.out.println("您输入的姓名有误,请您重新输入!");}}break;}else{System.out.println("您当前贡献点不足!");System.out.println("当前您的贡献点为:"+pro.getContribution());System.out.println("请您重新输入!");}}else {System.out.println("您输入的点数非法,请您重新输入!");}}}break;}}/*** 得到屏蔽姓名* @param other_pro 对方账户* @return 屏蔽姓名*/private static String getotherName(property other_pro) {String name = other_pro.getName();int flag = name.length();String other_name ="";if(flag==2)return other_name = name.replace(name.substring(1),"*");if(flag==3)return other_name=name.replace(name.substring(1),"**");else return other_name=name.replace(name.substring(2),"**");}/*** 取出贡献点* @param sca 扫描器* @param pro 登录的账户*/private static void sub_contribution(Scanner sca, property pro) {System.out.println("---------------------取款----------------------");while (true){System.out.println("请您输入待取点数:");int contr = sca.nextInt();if(contr>=0){if(contr<=pro.getContribution()) {pro.setContribution(pro.getContribution()-contr);System.out.println("您已成功取出"+contr+"点!");System.out.println("您当前共有贡献点:"+pro.getContribution());break;}System.out.println("您的余额不足!");System.out.println("当前余额为:"+pro.getContribution());System.out.println("请您重新输入!");}else{System.out.println("您输入的点数非法,请您重新输入!");}}}/*** 存款* @param sca 扫描器* @param pro 登录的账户*/private static void add_contribution(Scanner sca, property pro) {System.out.println("-----------------存款----------------------");System.out.println("请您输入待存的贡献点数:");int contr = sca.nextInt();pro.setContribution(pro.getContribution()+contr);System.out.println("您已成功存取 "+contr+" 点贡献点!");System.out.println("您当前共有贡献点:"+pro.getContribution());}/*** 退出登录*/private static boolean quit_porperty() {System.out.println("-------------------退出登录--------------------");System.out.println("您已退出登录!");return true;}/*** 展示属性* @param pro 登录的该账户*/private static void check_property(property pro) {System.out.println("----------------------属性------------------------");System.out.print("【");System.out.println("姓名:"+pro.getName());System.out.println("ID:"+pro.getID());System.out.println("年龄:"+pro.getAge());System.out.println("修为:"+pro.getQuality());System.out.println("种族:"+pro.getRace());System.out.print("贡献点:"+pro.getContribution());System.out.println("】");}/*** 用户操作界面*/private static void function() {System.out.println("------------欢迎来到用户操作界面------------");System.out.println("请您输入选择:");System.out.println("1.查询");System.out.println("2.交易");System.out.println("3.退出");System.out.println("4.注销");}/*** 进入注册/登录界面* @param sca 扫描器* @param proArrayList 集合*/private static void register(Scanner sca, ArrayList<property> proArrayList) {System.out.println("-----------------注册---------------------");property pro = new property();System.out.println("请您输入您的姓名:");String name = sca.next();pro.setName(name);System.out.println("请输入您的年龄:");int age = sca.nextInt();pro.setAge(age);System.out.println("请您输入您的种族:");String race = sca.next();pro.setRace(race);System.out.println("请您输入您的修为:");String quality = sca.next();pro.setQuality(quality);String ID;ID = getPropertyID(proArrayList);pro.setID(ID);System.out.println("请您输入登录密码:");String password = sca.next();pro.setPassword(password);System.out.println("尊敬的【"+name+"】道友,您的登录ID是:"+ID);proArrayList.add(pro);//添加到集合中}/*** 获取不重复的ID* @return ID*/private static String getPropertyID(ArrayList<property> proArrayList) {Random ran = new Random();while(true){StringBuilder sb=new StringBuilder();for (int i = 0; i < 9; i++) {sb.append(ran.nextInt(10));}String ID = sb.toString();property pro = getproByID(proArrayList,ID);if(pro==null)return ID;}}/*** 通过ID获得账户信息** @param proArrayList 集合* @param ID* @return 找到的账户信息(如果未找到,返回null)*/private static property getproByID(ArrayList<property> proArrayList, String ID) {for (int i = 0; i < proArrayList.size(); i++) {if(ID.equals(proArrayList.get(i).getID()))return proArrayList.get(i);}return null;}private static void menu() {System.out.println("-----------------欢迎道友来到仙盟---------------------");System.out.println("请您选择操作:");System.out.println("1.注册账户");System.out.println("2.登录系统");System.out.println("3.退出");}
}/*** 定义属性类*/
class property{private String name;//姓名private String ID;//身份号private String password;//密码private int age;//年龄private String race;//种族private String quality;//修为private int contribution;//贡献点public property(String name, String ID, String password, int age, String race, String quality, int contribution) {this.name = name;this.ID = ID;this.password = password;this.age = age;this.race = race;this.quality = quality;this.contribution = contribution;}public property() {}public String getQuality() {return quality;}public void setQuality(String quality) {this.quality = quality;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getID() {return ID;}public void setID(String ID) {this.ID = ID;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}public String getRace() {return race;}public void setRace(String race) {this.race = race;}public int getContribution() {return contribution;}public void setContribution(int contribution) {this.contribution = contribution;}
}

五、效果展示

1.账户注册

在这里插入图片描述
在这里插入图片描述

2.账户登录

在这里插入图片描述

(1)查询属性

在这里插入图片描述

(2)交易界面

在这里插入图片描述

(1)存款

在这里插入图片描述

(2)取款

在这里插入图片描述

(3)转账

在这里插入图片描述

(4)退出交易系统

在这里插入图片描述

(3)退出登录

在这里插入图片描述

(4)注销账户

在这里插入图片描述

此时我们再登录韩立的账户,发现已经不能登录了!

在这里插入图片描述

(5)登录【萧炎】的账户

在这里插入图片描述
刚才转账的1000贡献点已到账!


http://www.ppmy.cn/news/361942.html

相关文章

MAYA学习心得——起步 小魔

07.7.25 视频建模教程第一课1、按F键可以把所建物体最大化。2、W、E、R分别对应移动、旋转、缩放3、Alt鼠标左键透视图的旋转&#xff1b;Alt右键缩放4、数字键可以让物体填充或只出现曲线&#xff1a;1、2、3键可以使曲线增加&#xff1b;4键使物体只出现曲线&#xff1b;5、6…

正式开始修炼

由于是学通信的&#xff0c;不管在学校还是工作&#xff0c;都一直在与通信网络、设备打交道&#xff0c;对于计算机尤其是计算机编程都是纯属个人爱好&#xff0c;这方面多年摸打滚爬&#xff0c;根据工作需要学些软件工程、编程技术&#xff0c;但应用仅限于文本处理、数据库…

《设计模式的艺术——软件开发人员内功修炼之道》交流贴

《设计模式的艺术——软件开发人员内功修炼之道》一书正式出版发行&#xff0c;已在国内各大知名电子商务网站陆续上架。 当当网 亚马逊 京东网 在本书的作者简介和前言中&#xff0c;我都加上了CSDN技术博客的地址&#xff0c;如下图所示&#xff0c;&…

女程序媛的神奇修仙路

写这篇文章主要是想总结下自己的大学一年的生活&#xff0c;谈一下&#xff0c;作为计算机妹子&#xff0c;作为计算机小白的成长生活&#xff0c;以及自己的一些感悟&#xff0c;自己做出的一些改变自己的选择。 1.初中的我迷信运气 初中的时候&#xff0c;我学的还不错&…

西游:我的弟子们过于嚣张(三)

第三章 大家都散了吧   林玄降临。 所有弟子&#xff0c;皆双眸璀璨&#xff0c;对上方的林玄&#xff0c;崇拜的五体投地&#xff01; 也就只有这样的师尊&#xff0c;才有可能写出那种书籍。 也就只有这样的师尊&#xff0c;才能建造鸿蒙书阁&#xff01; 然而&#xf…

C语言实现实数和复数矩阵及其各种运算(五)

一、前言 本章开始&#xff0c;笔者将详细讲解矩阵的QR分解、特征值、特征向量等运算&#xff0c;并给出函数和测试demo的C代码&#xff0c;以及与matlab计算的结果&#xff1b;并且&#xff0c;本章相当于前面几章的大杂烩&#xff0c;前面所有的结构体、宏定义、函数本章基本…

修行

今天开始我的修行&#xff0c;每日以冷水洗脸&#xff0c;不让自己忘记&#xff01;

西游:我的弟子们过于嚣张(一)

第一章 准备苟到西游大劫结束&#xff01;   东山之东&#xff0c;霞光缭绕。 这里是东胜神洲与南瞻部洲的交界处&#xff0c;放眼望去&#xff0c;为蓝天与旷海。 海风吹过&#xff0c;充满生机与自然。 流光氤氲&#xff0c;仙云蒸腾。 一片不大的山头&#xff0c;屹立…