導航:首頁 > 編程語言 > 銀行賬戶java

銀行賬戶java

發布時間:2025-07-09 06:21:11

java語言程序設計:設計銀行賬戶類,屬性包括賬號、儲戶名稱、開戶時間、身份證號碼、存款余額等

寫個例子吧,既沒有分,又不付費。。。。真的是。。
public class account{
public static int serviceNum;
private String account;
private String password;
......
public String getAccount(){
return this.account;
}
public void setAccount(String account){
this.account = account;
}
public String getPassword(){
return this.password;
}
public void setPassword(String password){
this.password = password
}
public Account(String account,String password){
this.account = account;
this.password = password;
}
public Account(String account){
this.account = account;
}
@overrite
public String toString(){
return this.account + "-" + this.password;
}
}

❷ java定義一個類實現銀行賬戶的概念。

public class BankAccount {

String account ;
int account_num;

//構造函數
public BankAccount(String account,int account_num){
this.account=account;
this.account_num=account_num;
}
//存錢
public String addNum(int num){
account_num= account_num+num;
return "存錢成功";
}

//取錢
public String getNum(int num){
String result;
if(account_num>num){
account_num =account_num-num;
result="取錢成功";
}else{
result="賬戶余額不足,還剩"+account_num;
}
return result;
}

//顯示余額
public String displayNum(){
return "賬戶余額:"+account_num;
}

//顯示賬號
public String displayAccount(){
return "賬戶:"+account;
}

public static void main(String[] args){
BankAccount lucy = new BankAccount("lucy",100);
BankAccount jack = new BankAccount("jack",50);
//顯示他們各自的余額
System.out.println("===顯示他們各自的余額===");
System.out.println("lucy:"+lucy.displayNum());
System.out.println("jack:"+jack.displayNum());
//存錢取錢
System.out.println("===存錢取錢===");
System.out.println("lucy取50:"+lucy.getNum(50));
System.out.println("jack存200:"+jack.addNum(200));
//顯示賬戶 顯示余額
System.out.println("===存錢取錢===");
System.out.println(lucy.displayAccount()+""+lucy.displayNum());
System.out.println(jack.displayAccount()+""+jack.displayNum());

}

}

運行結果:
===顯示他們各自的余額===
lucy:賬戶余額:100
jack:賬戶余額:50
===存錢取錢===
lucy取50:取錢成功
jack存200:存錢成功
===存錢取錢===
賬戶:lucy賬戶余額:50
賬戶:jack賬戶余額:250

閱讀全文

與銀行賬戶java相關的資料

熱點內容
ug裝配體找不到文件部件已刪除 瀏覽:629
小網站怎麼弄出來 瀏覽:649
jsp表單加參數 瀏覽:607
蘋果5s手機老是卡屏 瀏覽:58
js給php變數賦值 瀏覽:446
雜志版本號是什麼意思 瀏覽:223
地圖特效代碼 瀏覽:192
去除思科配置文件中的號 瀏覽:196
運行的16位程序太多 瀏覽:1
蘋果mac用什麼軟體好學編程 瀏覽:681
ai中線段怎麼添加寬度配置文件 瀏覽:956
lol文件怎麼找不到game 瀏覽:142
aecc視頻教程 瀏覽:983
linux怎麼查看資料庫用戶名 瀏覽:182
cefs文件系統 瀏覽:404
學平面設計個編程哪個好 瀏覽:701
如何把編程文件轉為hex 瀏覽:80
清除蘋果地圖來自地址 瀏覽:233
已經打開的文件如何清理 瀏覽:685
視頻網站有什麼用 瀏覽:70

友情鏈接