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

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

代碼如下:

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();

}

}

  • 上一篇:CNC和CNC有什麽區別?
  • 下一篇:求MCPE0.9用pocketmine-mp的開服教程
  • copyright 2024編程學習大全網