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;
推荐阅读
- 推荐款单机游戏,推荐款单机游戏排行榜
- 如何有效营销基金,如何进行有效的游戏营销
- 苹果单机游戏助手,苹果 游戏助手
- python要懂函数吗 学python要背函数吗
- 便捷下载,便捷下载
- jquery中下列写法正确的是,下列关于jquery的描述错误的是
- jquery取消键盘模拟,js模拟键盘按下
- php168修改数据库 php修改数据表内容
- 3ds玩psp模拟器安卓版,3ds用最新ps模拟器