java大程序 银行管理系统(优化版)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
银行管理系统
【题目:编写程序,模拟银行账户功能。要求如下:
属性:账号(account)、储户姓名(name)、地址(address)、存款余额(balance)、最小余额(minBalance)
方法:存款(deposit)、取款(withdraw)、查询(query)
根据用户操作显示储户相关信息。】
package bank;
import java.util.ArrayList;
import java.util.Scanner;
public class Bank {
long account;//账号
String name,address;
static float balance = 0f;//存款余额
static float minBalance = 0f;//最小余额
float money;//钱数
public Bank(long account,String name,String address,float balance)
{
this.account = account;
= name;
this.address = address;
this.balance = balance;
}
public static float deposit(float money) //存款
{
float m = money+balance;
return m;
}
public static float withdraw(float money) //取款
{
float y = balance-money;
return y;
}
public static void query() //查询
{
System.out.println("您现有存款是:"+String.format("%.2f", balance));
}
public static void welcome()
{
System.out.println("请输入您的操作");
System.out.println("---------------------流程详单
------------------------------");
System.out.println("---------------------存款:
1---------------------");
System.out.println("---------------------取款:
2---------------------");
System.out.println("---------------------查询:
3---------------------");
System.out.println("---------------------退出:
0---------------------");
}
public String toString()
{
return"您的账户:"+account+",您的姓名:"+name+",您的地址:"+address+",您的账户余额:"+String.format("%.2f", balance);
}
public static void main(String[] args)
{
float w = 0f;
boolean flag = true;
@SuppressWarnings("resource")
Scanner scanner = new Scanner(System.in);
ArrayList
System.out.println("请输入账号");
long account = scanner.nextLong();
System.out.println("请输入姓名");
String name = scanner.next();
System.out.println("请输入地址");
String address = scanner.next();
while(flag)
{
welcome();
int a = scanner.nextInt();//流程判断
switch(a)
{
case 1:{
boolean lflag = true;
while(lflag)
{
System.out.println("请输入存款金额:");
float money = scanner.nextFloat();
float b =Bank.deposit(money);
w = w+b;
System.out.println("您现有存款是:"+String.format("%.2f", w));
System.out.println("请问您是否还要存款:是/否");
String check1 = scanner.next();
if(check1.equals("是"))
{
l flag = true;
}
if(check1.equals("否"))
{
balance = w;
w = 0f;
lflag = false;
}
}
}break;
case 2:
{
boolean lflag1 = true;
while(lflag1)
{
System.out.println("请输入取款金额:");
float money = scanner.nextFloat();
if(money>balance)
{
S ystem.out.println("取款额度超过现有钱数,请重新输入");
l flag1 = true;
}
else
{
float c =Bank.withdraw(money);
balance = c;
System.out.println("您现有存款是:"+String.format("%.2f", balance));
System.out.println("请问您是否还要取款:是/否");
String check2 = scanner.next();
if(check2.equals("是"))
{
l flag1 = true;
}
if(check2.equals("否"))
{
lflag1 = false;
}
}
}
}break;
case 3:query();break;