写一个银行账户的类,其中定义域包括,id号,账户余额,利率

package experience5;

import java.util.*;

public class Account {

private int id;

private double balance;

private double annualInterestRate;

private Date dateCreated;

public Account(){

    this(0,0,0);

     dateCreated = new Date();

}

public Account(int id,double balance,double annualInterestRate) {

    this.id=id;

    this.balance=balance;

    this.annualInterestRate=annualInterestRate;

     dateCreated = new Date();

}

public int geti() {

    return id;

}

public double getb() {

    return balance;

}

public double gtea() {

    return annualInterestRate;

}

public void seti(int id) {

    this.id=id;

}

public void setb(double balance) {

    this.balance=balance;

}

public void seta(double  annualInterestRate) {

    this.annualInterestRate= annualInterestRate;

}

public void dateCreated() {

    System.out.println(dateCreated);

}

public double getmonth() {

    return annualInterestRate/12;

}

public double getmonthst() {

    return balance* (annualInterestRate/12);

}

public void withDraw(double Draw) {

    balance= balance-Draw;

}

public void deposit(double d) {

    balance=balance+d;

}

public String toString() {

    return "  The id:"+id+"   "+"  has a balance="+balance+"      "+dateCreated;

}

public static void main(String[] args) {

    Account a=new Account(123,100,0.3);

    checkingaccount b=new checkingaccount(124,-10000,0.3,true);

    savingaccount c=new savingaccount(125,100,0.3);

    System.out.println(a.toString());

    System.out.println(b.toString());

    System.out.println(c.toString());

}

}

class checkingaccount extends Account {

    boolean s;//假设透支限定额是1000

    public checkingaccount(int a,double b,double c,boolean d) {

        seti(a);

        setb(b);

        seta(c);

        s=d;

    }

    public boolean gettrue() {

        if(getb()<-1000) {

            return false;

        }

        else return true;

    }

    public String toString() {

        return super.toString()+"    the count has "+s+" the checking";

    }

}

class savingaccount extends Account{

    public savingaccount(int a,double b,double c) {

        seti(a);

        setb(b);

        seta(c);

        }

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值