银行取钱java代码 java编写银行取款系统( 二 )


if(this.blance.doubleValue()amount){
System.out.println("the balance["+this.blance.doubleValue()+
"] is less than amount["+amount+"], please re-input amount");
System.out.println("withdrawing end failure");
return;
}
this.blance = this.blance.subtract(new BigDecimal(amount));
this.addTransaction("2", amount);
System.out.println("withdrawing end success");
}
public void showDetail(){
System.out.println("showDetail start");
System.out.println("----------------------");
System.out.println(this.toString());
System.out.println("----------------------");
System.out.println("showDetail end success");
}
}
public class Transaction{
private String type; //1 depositing 2 withdrawing
private double amount; //amount of money
private Date createDate;

public Transaction(String type, double amount) {
super();
this.type = type;
this.amount = amount;
this.createDate = new Date();
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public double getAmount() {
return amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
@Override
public String toString() {
return "Transaction [type=" + (type.equals("1")?"depositing":"withdrawing") + ", amount=" + amount
+ ", createDate=" + createDate + "]";
}
}
private void showMenu(Scanner reader){
System.out.println("--- Choose menu ---");
System.out.println("please input number 1-4 to choose menu;1:deposit money, 2:withdraw money, 3:view details or 4:exit");
if(reader.hasNextInt()){
int flag = reader.nextInt();
switch(flag){
case 1 :{
System.out.println(" please input amount:");
double amount = reader.nextDouble();
this.getCustomer().depositing(amount);
showMenu(reader);
}
case 2 :{
System.out.println(" please input amount:");
double amount = reader.nextDouble();
this.getCustomer().withdrawing(amount);
showMenu(reader);
}
case 3 :{
this.getCustomer().showDetail();
showMenu(reader);
}
case 4 :{
break;
}
default :{
System.out.println("invalid input ");
showMenu(reader);
}
}
}
System.out.println("Do you really want to exit? yes or no ");
reader.nextLine();
String outChoose = reader.nextLine();
if(!"YES".equals(outChoose.toUpperCase())!"Y".equals(outChoose.toUpperCase())){
showMenu(reader);
}
}
public static voidmain(String[] args){
System.out.println("--- Welcome to Test bank ---");
System.out.println("please input your name :");
Scanner reader=new Scanner(System.in);
Bank bank = new Bank();
if(reader.hasNextLine()){
bank.getCustomer().setName(reader.nextLine());
}
System.out.println("please input your address :");
if(reader.hasNextLine()){
bank.getCustomer().setAddress(reader.nextLine());
}
System.out.println("please input your phone number :");
if(reader.hasNextLine()){
bank.getCustomer().setPhoneNo(reader.nextLine());
}
System.out.println("please input your account number :");
if(reader.hasNextLine()){
bank.getCustomer().setAccountNo(reader.nextLine());
}
System.out.println("customer info :"+bank.getCustomer().toString());
bank.showMenu(reader);
}
}
java模拟银行取钱的一个类 里面构造函数有值,就是使用balance为0.0 为什么?public Account2(String accountNo, double balance2) {
this.accountNo = accountNo;

推荐阅读