91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

java編程 新賬戶類(Newaccount)(java繼承)

發布時間:2020-04-06 00:53:33 來源:網絡 閱讀:322 作者:夢T醒 欄目:編程語言

可記錄多次存取信息

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<account.transaction.size();i++)
        {
            System.out.println(account.transaction.get(i));
        }
    }
}
class Account 
{
    private int id=0;
    private double balance=0;
    static private double annualInterestRate=0;
    private Date dateCreated;
    public Account()
    {
        dateCreated=new Date();
    }
    public Account(int x,double y)
    {
        id=x;
        balance=y;
        dateCreated=new Date();
    }
    public void setId(int x)
    {
        id=x;
    }
    public int getId()
    {
        return id;
    }
    public void setBalance(double x)
    {
        balance=x;
    }
    public double getBalance()
    {
        return balance;
    }
    public void setAnnualInterestRate(double x)
    {
        annualInterestRate=x;
    }
    public double getAnnualInterestRate()
    {
        return annualInterestRate;
    }
    public Date getDateCreated()
    {
        return dateCreated;
    }
    public double getMonthlyInterestRate()
    {
        return annualInterestRate/12;
    }
    public double getMonthlyInterest()
    {
        return getMonthlyInterestRate()*balance;
    }
    public void withDraw(double money)
    {
        if(balance>=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(),""));
    }
}
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

会东县| 鞍山市| 五河县| 西贡区| 新营市| 米脂县| 怀化市| 浦江县| 同仁县| 铜梁县| 天镇县| 上饶市| 临沧市| 涞水县| 长沙市| 罗城| 大宁县| 天等县| 沛县| 东乡县| 启东市| 涡阳县| 彰武县| 屏南县| 双鸭山市| 勐海县| 新闻| 子长县| 安西县| 确山县| 嵊州市| 定襄县| 临沧市| 明水县| 大英县| 四会市| 大石桥市| 绥阳县| 丰县| 平邑县| 东安县|