简易ATM机

简易ATM机(代码如下):

/*
* 功能:简易银行系统
*/
package day8;

import java.util.Scanner;

/**
*
* @FengYan Huang Administrator
* 下午1:07:20
*/
public class test8_1 {
static int count=0;
static int n=-1;
static boolean flag=false;
static String[] user=new String[10];
static int[] identity={62220000,62220001,62220001,62220002,62220003,62220004,62220005,62220006,62220007,62220008,62220009};
static int[] password=new int[10];
static int[] balance=new int[10];
static Scanner scan=new Scanner(System.in);
public static void main(String[] args) {
fun();
}
public static void fun(){
System.out.println("***欢迎使用ATM机***");
System.out.println("***请选择服务类型***");
System.out.println("***开户***");
System.out.println("***登录***");
System.out.println("***退出***");
String str=scan.next();
if(str.equals("开户")){
register();
}else if(str.equals("登录")){
login();
}else if(str.equals("退出")){
exit();
}else{
System.out.println("很抱歉,无法识别您的操作,请重新选择!!!");
fun();
}
}
public static void login(){

System.out.println("请输入您的卡号:");
int id=scan.nextInt();
for (int i = 0; i < identity.length; i++) {
if(id==identity[i]){
System.out.println("请输入您的密码:");
int ps=scan.nextInt();

if(id==identity[i]&&ps!=password[i]){
System.out.println("温馨提示:");
count++;
System.out.println("您已经输错了"+count+"次密码");
System.out.println("请返回重新操作!");
if(count==3){
System.out.println("您今日的密码输入次数已达上限,卡片已经被吞");
System.out.println("您是否已经忘记了密码???");
System.out.println("请联系本行取回卡片");
fun();
}
login();
}

if(id==identity[i]&&ps==password[i]){
n=i;
System.out.println("***登录成功***");
System.out.println("***欢迎您***"+user[i]);
System.out.println("***请选择服务项目***");
fun1(user,identity,password,balance);

}

}else{
flag=true;
}
}
if(flag=true){
System.out.println("没找到您的卡号!");
System.out.println("请重新操作");
flag=false;
login();
}

}
public static void register(){
System.out.println("***欢迎注册本行银行卡***");
System.out.println("***请输入您的姓名***");
String name=scan.next();
System.out.println("***请输入您的密码***");
int ps=scan.nextInt();
System.out.println("***请确认输入您的密码***");
int ps1=scan.nextInt();
if(ps==ps1){
for (int i = 0; i < user.length; i++) {
if(user[i]==null){
user[i]=name;
password[i]=ps;
System.out.println("***注册成功***");
System.out.println("***您的账户名是:"+user[i]);
System.out.println("***请牢记您的卡号:"+identity[i]);
System.out.println("***请牢记您的密码:"+password[i]);
fun();
}else{
flag=true;
}
}
if(flag=true){
flag=false;
System.out.println("***非常抱歉***");
System.out.println("***本行注册用户已达上限***");
System.out.println("***本行注册用户已达上限***");
fun();
}

}else{
System.out.println("注册失败!!!您两次输入的密码不一样");
fun();
}
}
public static void exit(){
System.out.println("***谢谢您的使用***");
System.out.println("***欢迎再次光临***");
System.out.println("***如果您有好的建议,请联系本行(95555)***");
System.exit(0);
}
public static void fun1(String[] user,int[]identity,int[]password,int[]balance){
System.out.println("***改密***");
System.out.println("***查询***");
System.out.println("***存款***");
System.out.println("***取款***");
System.out.println("***转账***");
System.out.println("***退出***");
String str=scan.next();
if(str.equals("改密")){
changePassword(user,identity,password,balance);
}else if(str.equals("查询")){
insert(user,identity,password,balance);
}else if(str.equals("存款")){
deposit(user,identity,password,balance);
}else if(str.equals("取款")){
withdraw(user,identity,password,balance);
}else if(str.equals("转账")){
transfer(user,identity,password,balance);
}else if(str.equals("退出")){
exit();
}else{
System.out.println("您的操作有误,请重新选择:");
fun1(user,identity,password,balance);
}
}
public static void changePassword(String[] user,int[]identity,int[]password,int[]balance){
System.out.println("***"+user[n]+"***");
System.out.println("***欢迎使用改密系统***");
System.out.println("***请输入新密码:***");
int ps=scan.nextInt();
System.out.println("***请确认新密码:***");
int ps1=scan.nextInt();
if(ps==ps1){
System.out.println("您的密码已经修改成功!");
password[n]=ps;
System.out.println("请牢记您的密码:"+ps);
System.out.println("***系统自动返回ing***");
fun1(user,identity,password,balance);
}else{
System.out.println("两次输入密码不一样!");
System.out.println("请重新操作!");
changePassword(user,identity,password,balance);
}
}
public static void insert(String[] user,int[]identity,int[]password,int[]balance){
System.out.println("***"+user[n]+"***");
System.out.println("***欢迎使用查询系统***");
System.out.println("***您的账户余额为:***");
System.out.println(balance[n]+"元");
System.out.println("***系统自动返回ing***");
fun1(user,identity,password,balance);
}
public static void deposit(String[] user,int[]identity,int[]password,int[]balance){
System.out.println("***"+user[n]+"***");
System.out.println("***欢迎使用存款系统***");
System.out.println("***请输入存款金额***");
int depositmoney=scan.nextInt();
System.out.println("***请放入百元大钞***");
if(depositmoney%100==0){
System.out.println("您要存入的金额是:"+depositmoney+"元");
System.out.println("***系统处理ing***");
balance[n]+=depositmoney;
System.out.println("存款成功!!!");
System.out.println("您的账户余额为:"+balance[n]+"元");
System.out.println("***系统自动返回ing***");
fun1(user,identity,password,balance);
}else{
System.out.println("存款失败!!!");
System.out.println("您放入纸币有疑问,请重新操作");
deposit(user,identity,password,balance);
}
}
public static void withdraw(String[] user,int[]identity,int[]password,int[]balance){
System.out.println("***"+user[n]+"***");
System.out.println("***欢迎使用取款系统***");
System.out.println("***请输入取款金额(为100元的整数倍)***");
int withdrawmoney=scan.nextInt();
System.out.println("***系统处理ing***");
if(balance[n]>withdrawmoney&&withdrawmoney%100==0){
balance[n]-=withdrawmoney;
System.out.println("***正在为您取款ing***");
System.out.println("***请取走您的钞票***");
System.out.println("***您的账户余额为:"+balance[n]+"元***");
System.out.println("***取款成功***");
System.out.println("***系统自动返回ing***");
fun1(user,identity,password,balance);
}else{
System.out.println("***很遗憾!取款失败***");
System.out.println("***给您带来的不便深表遗憾***");
System.out.println("***可能是以下原因造成的:***");
System.out.println("***您的余额不足***");
System.out.println("***您输入的取款金额有误***");
System.out.println("***请重新操作***");
System.out.println("***系统自动返回ing***");
withdraw(user,identity,password,balance);
}
}
public static void transfer(String[] user,int[]identity,int[]password,int[]balance){
System.out.println("***"+user[n]+"***");
System.out.println("***欢迎使用转账系统***");
System.out.println("***请输入您要转入的对方名字:");
String username=scan.next();
for (int i = 0; i < user.length; i++) {
if(username.equals(user[i])){
System.out.println("您要转入的是:"+user[i]+"的账户");
System.out.println("请输入转入的金额");
int transfermoney=scan.nextInt();
System.out.println("***正在为您处理ing***");
if(transfermoney>0&&balance[n]>transfermoney){

balance[n]-=transfermoney;
balance[i]+=transfermoney;
System.out.println("***转账成功***");
System.out.println("您的账户余额为:"+balance[n]);
System.out.println("***系统自动返回ing***");
fun1(user,identity,password,balance);
}else{
System.out.println("转账失败");
System.out.println("可能是您的账户余额不足");
System.out.println("可能是您输入的金额有误");
System.out.println("请返回重新操作");
transfer(user,identity,password,balance);
}
}
else{
flag=true;
}

}
if(flag==true){
System.out.println("没找到账户!");
System.out.println("请重新操作!");
flag=false;
transfer(user,identity,password,balance);
}

}
}

上一篇:情感分析的现代方法(包含word2vec Doc2Vec)


下一篇:激活office 2010