一、题目要求
编写一个ATM管理系统,语言不限,要求应包括以下主要功能:
(1)开户,销户
(2)查询账户余额
(3)存款
(4)取款
(5)转账(一个账户转到另一个账户)等
二.代码提交
开户
public static void account()
{
System.out.print("请输入用户名:");
Scanner name1=new Scanner(System.in);
name=name1.nextLine();
System.out.print("请输入密码:");
Scanner passworld1=new Scanner(System.in);
passworld=passworld1.nextLine();
user.put(name,passworld);
message.put(name,0f);
System.out.println("开户成功");
}
销户
public static void selling()
{
System.out.print("请输入用户名:");
Scanner name1=new Scanner(System.in);
name=name1.nextLine();
System.out.print("请输入密码:");
Scanner passworld1=new Scanner(System.in);
passworld=passworld1.nextLine();
if(user.containsKey(name))
{
String mypassworld=user.get(name);
if(mypassworld.equals(passworld))
{
user.remove(name);
message.remove(name);
System.out.println("销户成功");
}
else
System.out.println("用户密码不正确");
}
else
System.out.println("不存在该用户");
}
余额查询
public static void inquire() {//余额查询
System.out.print("请输入用户名:");
Scanner name1=new Scanner(System.in);
name=name1.nextLine();
System.out.print("请输入密码:");
Scanner passworld1=new Scanner(System.in);
passworld=passworld1.nextLine();
if(user.containsKey(name))
{
String mypassworld=user.get(name);
if(mypassworld.equals(passworld)) {
amount=message.get(name);
System.out.printf("你的余额为:"+"%.2f",amount);
System.out.println();
}
else
System.out.println("用户密码不正确");
}
else
System.out.println("不存在该用户");
}
存款
public static void deposit() {//存款
System.out.print("请输入用户名:");
Scanner name1=new Scanner(System.in);
name=name1.nextLine();
System.out.print("请输入密码:");
Scanner passworld1=new Scanner(System.in);
passworld=passworld1.nextLine();
if(user.containsKey(name))
{
String mypassworld=user.get(name);
if(mypassworld.equals(passworld)) {
amount=message.get(name);
System.out.print("请输入存入的金额:");
Scanner money1=new Scanner(System.in);
float money=money1.nextFloat();
amount+=money;
message.put(name, amount);//把存取的金额存到哈希表中
System.out.printf("存款成功你的余额为:"+"%.2f",amount);
System.out.println();
}
else
System.out.println("用户密码不正确");
}
else
System.out.println("不存在该用户");
}
取款
public static void withdrawal() {//取款
System.out.print("请输入用户名:");
Scanner name1=new Scanner(System.in);
name=name1.nextLine();
System.out.print("请输入密码:");
Scanner passworld1=new Scanner(System.in);
passworld=passworld1.nextLine();
if(user.containsKey(name))
{
String mypassworld=user.get(name);
if(mypassworld.equals(passworld)) {
amount=message.get(name);
System.out.print("请输入取出的金额:");
Scanner money1=new Scanner(System.in);
float money=money1.nextFloat();
if(amount<money)
System.out.println("取款失败,余额不足");
else {
amount=amount-money;
message.put(name, amount);
System.out.printf("取款成功你的余额为:"+"%.2f",amount);
System.out.println();
}
}
else
System.out.println("用户密码不正确");
}
else
System.out.println("不存在该用户");
}
转账
public static void transfer() {//转账
System.out.print("请输入用户名:");
Scanner name1=new Scanner(System.in);
name=name1.nextLine();
System.out.print("请输入密码:");
Scanner passworld1=new Scanner(System.in);
passworld=passworld1.nextLine();
if(user.containsKey(name))
{
String mypassworld=user.get(name);
if(mypassworld.equals(passworld)) {
amount=message.get(name);
System.out.print("请输入转出的金额:");
Scanner money1=new Scanner(System.in);
float money=money1.nextFloat();
System.out.print("请输入要转入的账户:");
Scanner name2=new Scanner(System.in);
String name3=name2.nextLine();//要转入的账户
if(user.containsKey(name3)) {
if(amount<money) {
System.out.println("转账失败,余额不足");
}
else {
amount=amount-money;
message.put(name, amount);
message.put(name3, money);
System.out.printf("取款成功你的余额为:"+"%.2f",amount);
System.out.println();
}
}
else
System.out.println("要转入的账户不存在");
}
else
System.out.println("用户密码不正确");
}
else
System.out.println("不存在该用户");
}