㈠ 用java編程設計一個銀行賬戶類,其中包括以下內容,並用字元界面模擬存款和取款過程。
import java.util.Scanner;
public class ZH {
private String zh;//賬戶
private String password;//密碼
private String openTime;//開戶時間
private String sfz;//身份證號
private double je;//存款金額
public String getZh() {
return zh;
}
public void setZh(String zh) {
this.zh = zh;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getOpenTime() {
return openTime;
}
public void setOpenTime(String openTime) {
this.openTime = openTime;
}
public String getSfz() {
return sfz;
}
public void setSfz(String sfz) {
this.sfz = sfz;
}
public double getJe() {
return je;
}
public void setJe(double je) {
this.je = je;
}
//存款方法
public void ck(double je){
this.je=this.je+je;//存入的金額加上原有的金額
}
//取款方法
public void qk(double je){
if(je>this.je){//取款金額大於余額
System.out.println("存款余額不足");
}else{
this.je=this.je-je;//原有的金額減去取出的金額
}
}
public static void main(String[] args) {
ZH zh = new ZH();//初始化一個賬戶信息
zh.setJe(10000.0);//向zh賬戶添加余額
zh.setOpenTime("2013.12.3");//向zh賬戶添加開發時間
zh.setPassword("123456");//向zh賬戶添加密碼
zh.setSfz("123456789");//向zh賬戶添加身份證
zh.setZh("zhangsan");//向zh賬戶添加賬號
System.out.println("歡迎光臨模擬銀行");
Scanner scan = new Scanner(System.in);
int count=0;//記錄輸入錯誤的次數
while(1==1){//循環
System.out.println("請輸入賬號");
String zhm=scan.next();
System.out.println("請輸入密碼");
String mm=scan.next();
if(zhm.equals(zh.getZh()) && mm.equals(zh.getPassword())){//輸入的信息與zh賬戶信息的密碼和賬號一致
while(1==1){
System.out.println("當前余額為:"+zh.getJe()+"元。請選擇操作:1.存款;2.取款;3.退出(只能輸入數字)");
String cz=scan.next();
switch (Integer.parseInt(cz)) {
case 1:
System.out.println("請輸入存款金額(輸入小數)");
double ckje=scan.nextDouble();
zh.ck(ckje);
System.out.println("實施存款:"+ckje+"元,當前余額為"+zh.getJe()+"元");
break;
case 2:
System.out.println("請輸入取款金額(輸入小數)");
double qkje=scan.nextDouble();
zh.qk(qkje);
System.out.println("實施取款:"+qkje+"元,當前余額為"+zh.getJe()+"元");
break;
case 3:
break;
default:
System.out.println("暫無此功能");//輸入1或者2、3以外的操作
break;
}
if("3".equals(cz)){
break;
}
}
System.out.println("退出操作");
break;
}else{
if(count>=3){
System.out.println("已輸入錯誤三次,賬號被鎖");
break;//結束循環
}else{
System.out.println("賬號或密碼錯誤,請重新輸入");
count++;//錯誤一次count+1
continue;//進入下次循環
}
}
}
}
}
㈡ 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語言程序設計:設計銀行賬戶類,屬性包括賬號、儲戶名稱、開戶時間、身份證號碼、存款余額等
寫個例子吧,既沒有分,又不付費。。。。真的是。。
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;
}
}