Java中在银行系统中有账户类型,进行基本存取款操作
Posted 薛千凝
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java中在银行系统中有账户类型,进行基本存取款操作相关的知识,希望对你有一定的参考价值。
问题
Account账户类有以下属性
accNo //账户账号
accName //账户姓名
accPassword //账户密码
accTelno //账户手机号
accBalance //账户余额
accType //账户类型 0:储蓄账户, 1:信用账户
1. 完成类的设计,属性使用合适的数据类型;其中 账户类型 0表示储蓄账户, 1表示信用账户
2. 给各属性添加赋值与取值方法(set,get)
3. 设计账户存款 depoist、取款 withdraw 两个方法,方法内部简单实现即可,
需要注意方法定义的结构(参数列表、返回值)
4. 创建两个银行账户对象,分别是储蓄账户与信用账户,
5. 给两个账户对象信息赋值,并显示输出账户的信息
6. 将第一个账户的手机号修改为1833893849
7. 在第二个账户中进行存款1000元与取款500元,并输出账户最新余额
/*
Account账户类有以下属性
accNo //账户账号
accName //账户姓名
accPassword //账户密码
accTelno //账户手机号
accBalance //账户余额
accType //账户类型 0:储蓄账户, 1:信用账户*/
public class Account
private int accNo;
private String accName;
private String accPassword;
private long accTelno;
private int accBalance;
private String accType;
public Account(int accNo,String accName, String accPassword,long accTelno,int accBalance,String accType)
this.accNo=accNo;
this.accName=accName;
this.accPassword=accPassword;
this.accTelno=accTelno;
this.accBalance=accBalance;
this.accType=accType;
public void sc()
//账户判断
if (this.accType == "0")
this.accType="储蓄账户";
else
if(this.accType == "1")
this.accType="信用账户";
System.out.println(this.accNo+","+this.accName+","+this.accPassword+","+this.accTelno+","+this.accBalance+","+this.accType);
public int getAccNo()
return accNo;
public String getAccName()
return accName;
public String getAccPassword()
return accPassword;
public long getAccTelno()
return accTelno;
public int getAccBalance()
return accBalance;
public String getAccType()
return accType;
public void setAccNo(int accNo)
this.accNo = accNo;
public void setAccName(String accName)
this.accName = accName;
public void setAccPassword(String accPassword)
this.accPassword = accPassword;
public void setAccTelno(long accTelno)
this.accTelno = accTelno;
public void setAccBalance(int accBalance)
this.accBalance = accBalance;
public void setAccType(String accType)
this.accType = accType;
//存款
public void desper(int x)
this.accBalance =this.accBalance + x;
System.out.println("恭喜您存入:"+ this.accBalance);
//取款
public void withdraw(int y)
this.accBalance = this.accBalance - y;
System.out.println("您以取出:"+y+"账户剩余:"+this.accBalance);
2、测试类
/*
Account账户类有以下属性
accNo //账户账号
accName //账户姓名
accPassword //账户密码
accTelno //账户手机号
accBalance //账户余额
accType //账户类型 0:储蓄账户, 1:信用账户*/
public class AccountTest
public static void main(String[] args)
Account account = new Account(1001,"张三","123456",18700000000l,0,"1");
Account account1 =new Account(1002,"李四","123456",15600000000l,0,"0");
account.sc();
account1.sc();
account.setAccTelno(18888888888l);
account.sc();
account.desper(1000);
account.withdraw(200);
以上是关于Java中在银行系统中有账户类型,进行基本存取款操作的主要内容,如果未能解决你的问题,请参考以下文章