成都创新互联网站制作重庆分公司

java编程新账户类(Newaccount)(java继承)

可记录多次存取信息

创新互联建站2013年开创至今,先为双流等服务建站,双流等地企业,进行企业商务咨询服务。为双流企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

import java.util.ArrayList;
import java.util.Date;
import java.util.Scanner;//声明

public class TestNewaccount //测试类
{
    public static void main(String[] args) 
    {
        NewAccount account = new NewAccount("Mike",1122,1000);
        account.setAnnualInterestRate(1.5/100);
        account.deposit(30);
        account.deposit(40);
        account.deposit(50);
        account.withDraw(5);
        account.withDraw(4);
        account.withDraw(2);
        for(int i=0;i=money)
        balance-=money;
    }
    public void deposit(double money)
    {
        balance+=money;
    }
}
class Transaction//用户交易信息类
{
    private char type;
    private Date date;
    private double money;
    private double balance;
    private String description;
    public Transaction(char type,double money,double balance,String description)
    {
        this.type=type;//交易类型(取款,存款)
        date=new Date();//时间
        this.money=money;//存取的多少
        this.balance=balance;//交易完还剩多少钱
        this.description=description;//交易备注
    }
    public String toString()
    {
        return "Type:"+type+"  Money:"+money+"  Balance:"+balance+"  Date:"+date+" "+description;
    }
}
class NewAccount extends Account//子类
{
    private String name;//新增变量
    ArrayList transaction=new ArrayList();//ArrayList方法
    public NewAccount(String name,int id,double balance)
    {
        super(id,balance);
        this.name=name;
    }
    public void withDraw(double x)//取钱
    {
        if(getBalance()>x)
        {
            setBalance(getBalance()-x);
            transaction.add(new Transaction('W',x,getBalance(),""));//往ArrayList方法中加元素
        }
    }
    public void deposit(double x)//存钱
    {
        setBalance(getBalance()+x);
        transaction.add(new Transaction('D',x,getBalance(),""));
    }
}

分享题目:java编程新账户类(Newaccount)(java继承)
分享链接:http://cxhlcq.com/article/jjedds.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部