银行账户管理系统,非链表。
Account:
import java.util.Scanner;
public class Account {
public static String number;
public static String name=null;
public static String bank=null;
public static int money=0;
public static int key;//密码要设定格式限制,隐藏输入,确定选项!
public static int date;
private int num;//用来作为存取款的中间值
private int n;//用来选择操作业务
public Account(String number,String name,String bank,int money,int key,int date)
{this.number=number;
this.name=name;
this.bank=bank;
this.money=money;
this.key=key;
this.date=date;
}
Scanner in=new Scanner(System.in);
public void service(int n)
{switch(n) {
case 1:
System.out.println(“请输入您想取款的金额”);
in.hasNextInt();
num=in.nextInt();
if(num>this.money)
{System.out.println(“您输入的金额有误,请重新选择业务!”);
}
else
{this.money-=num;
System.out.println(“取款成功!您当前余额为:”+this.money);
}
break;
case 2:
System.out.println(“请输入您想存款的金额:”);
in.hasNextInt();
num=in.nextInt();
this.money+=num;
System.out.println(“存款成功!您当前余额为:”+this.money);
break;
case 3:
System.out.println(“您当前的可用余额为:”+this.money);
break;
case 4:
System.out.println(“退卡成功!请取走您的银行卡”);
System.exit(1);
break;
default:
System.out.println(“您选择的业务有误,请重新选择业务!”);
}
}
}
测试:import java.util.Scanner;
public class Text {
public static void main(String[] args) {
// TODO Auto-generated method stub
Account a=null;
Scanner n=new Scanner(System.in);
a=new Account("201700208101","陈彬锋","中国农业银行梧州支行",2000,123,2019101);
/*System.out.println(a.number);
System.out.println(a.name);
System.out.println(a.bank);
System.out.println(a.money);
System.out.println(a.key);
System.out.println(a.date); */
System.out.println("请输入您的登录密码:");
n.hasNextInt();
int checkkey;
checkkey=n.nextInt();
int m=1;
while(m<3){
if(checkkey!=a.key)
{System.out.println("您输入的密码错误!请重新输入:");
n.hasNextInt();
checkkey=n.nextInt();
m++;
}
else
{System.out.println("您输入的密码正确,请选择您想进行的业务");
System.out.println("1)取款");
System.out.println("2)存款");
System.out.println("3)查询余额");
System.out.println("4)退卡");
int select;
while(true) {
n.hasNext();
a.service(n.nextInt());
}
}
if(m==3) {
System.out.println("您输入次数已达上限!强制退出系统!");
System.exit(1);
}
}
}
}