當前位置:編程學習大全網 - 網站源碼 - 編寫程序,模擬銀行帳戶功能。

編寫程序,模擬銀行帳戶功能。

代碼如下:

public class Account {

static double min = 10;

String account, name, address;

float balance = 0.0f;

public Account(String account, String name, String address, float balance) {

this.account = account;

this.name = name;

this.address = address;

this.balance = balance;

System.out.println("您賬戶中原有余額:" + balance);

}

public void deposit(float f) {

this.balance += f;

System.out.println("現存入:" + f);

System.out.println("當前余額:" + balance);

}

public void withdraw(float f) {

if (balance - f < min) {

System.out.println("余額不夠,至少保留余額:" + min);

} else {

balance = balance - f;

System.out.println("當前余額:" + balance);

}

}

public void query() {

System.out.println("您的當前余額:" + balance);

}

public static void main(String[] args) {

Account jame = new Account("111111", "張傑", "浙江大學", 200);

jame.deposit(350);

jame.withdraw(300);

jame.withdraw(300);

jame.query();

}

}

  • 上一篇:如何建立壹個網頁?如何播放網頁上的背景音樂?為什麽通過FTP上傳後還要鏈接代碼?
  • 下一篇:關於前端jquery:選擇文件var files=$("#img").files,輸出files是undefined。求解
  • copyright 2024編程學習大全網