package com.sorce.bankSys;
import java.util.Scanner;
import sun.security.action.GetBooleanAction;
public class BankSys {
private int uId; //这写好像用不上,你自己看着加吧
private String uName;
private String address;
private double minMon=0.50;
private double money=1000.50;
public static void main(String[] args) {
String answer;
// TODO Auto-generated method stub
System.out.println("欢迎进入存取款系统!");
System.out.println("---------------------");
do{
System.out.println("1.取款 \t2.查询余额\t3.存款");
Scanner sc=new Scanner(System.in);
BankSys bank=new BankSys();
int num=sc.nextInt();
switch (num) {
case 1:
bank.get();
break;
case 2:
bank.search();
break;
case 3:
bank.deposit();
break;
default:
break;
}
System.out.println("是否继续?(y/n)");
answer=sc.next();
}while(answer.equals("y"));
System.out.println("程序结束");
}
public void deposit(){
Scanner sc=new Scanner(System.in);
System.out.println("请输入存款金额:");
double input=sc.nextInt();
System.out.println("您的帐户原有余额为:"+money+"元");
System.out.println("已存入:"+input+"元");
money+=input;
System.out.println("您的帐户最终存款余额为:"+money+"元");
}
public void search(){
System.out.println("您的帐户余额为:"+money+"元");
}
public void get(){
Scanner sc=new Scanner(System.in);
System.out.println("请输入取款金额:");
double input=sc.nextInt();
if (money System.out.println("您的帐户余额不足!");
}else{
System.out.println("您本次取出:"+input+"元");
money-=input;
System.out.println("剩余金额为:"+money+"元");
}
}
}
import java.text.SimpleDateFormat;
import java.util.Date;
public class Bank {
private String account = "";
private String name = "";
private String address = "";
private long balance = 0l;
private final long minBalance = 100l;// 最少存款应该是固定的
public Bank() {
}
public Bank(String account, String name, String address, long balance) {
this.account = account;
this.name = name;
this.address = address;
this.balance = balance;
}
public String query() {
String result = "尊敬的客户您好!你的账号为:" + account + ",户主:" + name + ",卡中的余额为:" + minBalance;
return result;
}
public void fetchMoney(long money) {
if (balance < minBalance) {
System.out.println("尊敬的客户您好!您账号的余额不足"+ minBalance+"不能取款");
} else {
balance = balance-money;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("尊敬的客户您好!您在"+dateFormat.format(new Date())+"取款"+money+"元,账号中的余额为:"+balance+"元");
}
}
public void deposit(long money) {
balance = balance+money;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("尊敬的客户您好!您在"+dateFormat.format(new Date())+"存款"+money+"元,账号中的余额为:"+balance+"元");
}
public static void main(String[] args) {
Bank bank = new Bank("123456789","wangwenjun","Beijing",10000);
bank.query();
bank.deposit(1000);
bank.query();
bank.fetchMoney(1000);
bank.query();
bank.fetchMoney(10000);
bank.query();
bank.fetchMoney(10000);
}
}
////////////////////////////测试如下
尊敬的客户您好!您在2009-04-09 16:53:40存款1000元,账号中的余额为:11000元
尊敬的客户您好!您在2009-04-09 16:53:40取款1000元,账号中的余额为:10000元
尊敬的客户您好!您在2009-04-09 16:53:40取款10000元,账号中的余额为:0元
尊敬的客户您好!您账号的余额不足100不能取款