bank账户

初学类:

import java.util.Scanner;
import java.io.*;
public class Bank {

String name;
static int count;
int yuer;
String code;
int password;
public Bank(String name,int count,int yuer,String code,int password) {
	this.name=name;
	this.count=count;
	this.yuer=yuer;
	this.code=code;
	this.password=password;
	
}

public void setname(String name) {
	this.name=name;
}
public void setcode(String code) {
	this.code=code;
}
public void setpassword(int password) {
	this.password=password;
}
static void show(Bank x) {
	System.out.println("账户名为:"+x.name+"账户号为:"+x.count);
}
static void searchyuer(Bank x) {
	System.out.println("当前余额为"+x.yuer);
}
static void zhuanzhang(Bank x,int zzje,Bank duixiang) {
	if(pd(x,zzje))  {  
	                    x.yuer-=zzje; duixiang.yuer+=zzje;
                        System.out.println("转账成功!");
                        System.out.println("当前余额为:"+x.yuer);}
	else if(!pd(x,zzje)) { System.out.println("余额不足,无法转账!");searchyuer(x);}
	
}
static void cunkuan(Bank x,int cunkuanjiner) {
	x.yuer+=cunkuanjiner;
	System.out.println("存款成功!");
	searchyuer(x);
}
static boolean pd(Bank x,int je) {
	boolean b=false;
if(x.yuer>=je)	b=true;
	return b;
}
static boolean pd2(Bank x,int password) {
	if(password==x.password)
	return true;else return false;
}
static void qk(Bank x,int qkje) {
	if(pd(x,qkje))  {  x.yuer-=qkje;
	System.out.println("取款成功!");
	searchyuer(x);
	}
	else {
		System.out.println("余额不足!");
		searchyuer(x);
	}
}

public static void main(String args[]) {

Bank shuzu[]=new Bank[100];
for(int v=0;v<100;v++) shuzu[v]= new Bank("null",0,0,"null",0);
shuzu[1]=new Bank("李昱龙",1,1000,"1",12);
int y=1;
while(true) {
System.out.println("请输入需要执行的操作");
System.out.println("***1建立新的银行账户***");
System.out.println("***2登录银行账户***");
System.out.println("***3退出系统***");
Scanner input=new Scanner(System.in);
int a=input.nextInt();
if(a==1) {
	shuzu[++y]=new Bank("null",y,0,"null",0);shuzu[y].count=y;
	System.out.print("请输入新的用户名:");
	try {BufferedReader in=new BufferedReader
		    (new InputStreamReader(System.in));
		    shuzu[y].setname(in.readLine());
		    }catch(IOException e) {}
	System.out.print("请设置登录密码:");
	try {BufferedReader in=new BufferedReader
		    (new InputStreamReader(System.in));
		    shuzu[y].setcode(in.readLine());
		    }catch(IOException e) {}
	System.out.print("请设置取款密码:");
	try {BufferedReader in=new BufferedReader
		    (new InputStreamReader(System.in));
		    shuzu[y].setpassword(Integer.valueOf(in.readLine()));
		    }catch(IOException e) {}
	System.out.println("账户设置成功!");
	show(shuzu[y]);
	}
if(a==2) {
	String s="";int i=0;
	System.out.print("请输入账户号:");
	try {BufferedReader in=new BufferedReader
		    (new InputStreamReader(System.in));
		    i=Integer.valueOf(in.readLine());
		    }catch(IOException e) {}
	if(shuzu[i].password==0) { System.out.println("无此账户!");continue;}
	System.out.print("请输入登录密码:");
	try {BufferedReader in=new BufferedReader
		    (new InputStreamReader(System.in));
		    s=in.readLine();
		    }catch(IOException e) {}
	if(s.equals(shuzu[i].code)) {
		System.out.println("登录成功!");
		System.out.println("***请选择操作***");
		System.out.println("***1余额查询操作***");
		System.out.println("***2取款操作***");
		System.out.println("***3存款操作***");
		System.out.println("***4转账操作***");
		System.out.println("***5退出系统***");
		Scanner sc=new Scanner(System.in);
		int b=input.nextInt();
		if(b==1) { shuzu[i].searchyuer(shuzu[i]);}
		if(b==2) {
				   System.out.println("请输入取款密码:");
		           Scanner put=new Scanner(System.in);
		           int c=Integer.valueOf(put.nextInt()); 
		               if(pd2(shuzu[i],c))
		               {System.out.println("输入取款金额:");  
		               Scanner Input=new Scanner(System.in);
		               int d=Input.nextInt();  qk(shuzu[i],d);
		               } 
		           	   else System.out.println("密码错误!");  
		          }
		if(b==3) {
			      System.out.println("输入存款金额:");
			      Scanner In=new Scanner(System.in);
			      int c=In.nextInt(); 
			      cunkuan(shuzu[i],c);
		        }
		if(b==4) {   
			      System.out.println("输入转账账号:");
	              Scanner In=new Scanner(System.in);
	              int c=In.nextInt();
	              if(shuzu[c].password==0) { System.out.println("无此账户!");continue;}
	              System.out.println("输入转账金额:");
	              int zzje=In.nextInt();
	              System.out.println("输入支付密码:");
				  int k=In.nextInt();
				  if(k==shuzu[i].password) 
					      zhuanzhang(shuzu[i],zzje,shuzu[c]);      
                  else    {System.out.println("支付密码错误!");continue;}
	                                         
		}
	    if(b==5) break;
	}
	else System.out.println("账户号或者密码错误!");
}
if(a==3) break;
}	

}

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值