银行管理系统
【题目:编写程序,模拟银行账户功能。
要求如下:
属性:账号(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<Bank>list = new 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;
case 0:flag=false;break;
}
}
Bank bank1 = new Bank(account,name,address,balance);
list.add(bank1);
for (Bank seek:list)
{
System.out.println(seek);
}
}
}
使用知识点:float应用,保留两位小数format方法应用,集合ArrayList及遍历,equal 比较方法应用,输入方法应用,面向对象构架,标志位布尔类型的设置及退出,方法的调用与返回等。