📄 testbankaccount.java
字号:
/*
* testBankAccount.java
*
* Created on 2008年4月4日, 下午8:47
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
import javax.swing.JOptionPane;
public class testBankAccount {
/** Creates a new instance of testBankAccount */
public static void main (String []args) {
String str="";
for(int i=0;i<350;i++){
str="";
bankAccount bobsAccount, marysAccount, biffsAccount;
bobsAccount = bankAccount.example1();
marysAccount = bankAccount.example2();
biffsAccount = bankAccount.emptyAccountExample();
bobsAccount.deposit(i*10-1);
marysAccount.setName("Mary");
marysAccount.deposit(i*10);
biffsAccount.deposit(i*10+1);
str=str+bobsAccount+marysAccount+biffsAccount;
}
System.out.println(str);
}
}
class bankAccount{
private static int LastAccountNumber=0;
private String name;
private int accountNumber;
private float balance;
public bankAccount() {
name="";
balance=0;
accountNumber=++LastAccountNumber;
}
public bankAccount(String initName){
name=initName;
balance=0;
accountNumber=++LastAccountNumber;
}
public bankAccount(String initName,float newBalance){
name=initName;
balance=newBalance;
accountNumber=++LastAccountNumber;
}
public static bankAccount example1() {
bankAccount ba = new bankAccount();
ba.setName("LiHong");
ba.deposit(1000);
return ba;
}
public static bankAccount example2() {
bankAccount ba = new bankAccount();
ba.setName("ZhaoWei");
ba.deposit(1000);
ba.deposit(2000);
return ba;
}
public static bankAccount emptyAccountExample() {
bankAccount ba = new bankAccount();
ba.setName("HeLi");
return ba;
}
public float deposit(float anAmount) {
balance += anAmount;
return balance;
}
public float withdraw(float anAmount) {
if (anAmount <= balance)
balance -= anAmount;
return anAmount;
}
public void setName(String aName)
{
name = aName;
}
public int getAccountNumber()
{
return accountNumber;
}
public String getName()
{
return name;
}
public float getBalance()
{
return balance;
}
public String toString()
{
return("AccountNumber :"+new java.text.DecimalFormat("000000").format(accountNumber)+"\n"+
"Name :"+name+"\n"+
"Balance :" +new java.text.DecimalFormat("$0.00").format(balance)+"\n\n");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -