创建简单的银行账户类,包括开户人、账号、和存款余额3个属性,以及查询余额、存款、取款等方法。创建两个账户验证类的设计。
完整代码如下:
package pk1;
import java.util.Scanner;
public class java {
String name="";
String number="";
int account=0;
public java(String na,String num,int acc) {
this.name=na;
this.number=num;
this.account=acc;
}
public void cxaccount() {
System.out.println(this.name+this.number+"您的账户余额为:"+this.account);
}
public void ck() {
System.out.println("请输入要存入的金额:");
Scanner sc=new Scanner(System.in);
this.account+=sc.nextInt();
this.cxaccount();
}
public void qk() {
System.out.println("请输入要取出的金额:");
Scanner sc=new Scanner(System.in);
int qk=sc.nextInt();
if(qk>this.account)
qk=this.account;
this.account-=qk;
this.cxaccount();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
java a=new java("zhangsan","2002",67689);
a.ck();
a.qk();
java b=new java("lisi","3006",893129034);
b.ck();
b.qk();
}
}