You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.3 KiB
43 lines
1.3 KiB
|
|
public class BankAccount {
|
|
private String accountNumber;
|
|
private String ownerName;
|
|
private double balance;
|
|
public BankAccount(String accountNumber, String ownerName, double balance){
|
|
this.accountNumber = accountNumber;
|
|
this.ownerName = ownerName;
|
|
this.balance=0.0;
|
|
}
|
|
public void deposit(double amount){
|
|
if ( amount >0.0){
|
|
this.balance+=amount;
|
|
System.out.printf("存款成功,余额为:%f\n",this.balance);
|
|
} else{
|
|
System.out.println("存款失败,金额必须大于0.0\n");
|
|
}
|
|
}
|
|
public void withdraw (double amount){
|
|
if (amount>0.0 &&amount<this.balance){
|
|
this.balance-=amount;
|
|
System.out.printf("取款成功,余额为:%f\n",this.balance);
|
|
} else{
|
|
System.out.println("取款失败,金额必须大于0.0且小于余额\n");
|
|
}
|
|
}
|
|
public double getbalance(){
|
|
return balance;
|
|
}
|
|
public String getAccountNumber(){
|
|
return accountNumber;
|
|
}
|
|
public String getOwnerName(){
|
|
return ownerName;
|
|
}
|
|
public void setAccountNumber(String accountNumber){
|
|
this.accountNumber = accountNumber;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|