• JAVA编程练习 账户对象创建(账户名 余额 利息 日期等)


    自带测试类
    源代码:

    package testaccount;
    public class TestAccount{
    public static void main(String args[]){
    Account ss=new Account(1122,20000);
    ss.setannualInterestRate(4.5);
    ss.withDraw(2500);
    ss.deposit(3000);
    System.out.println("The ss's id is "+ ss.getid());
    System.out.println("The ss's balance is "+ ss.getbalance());
    System.out.println("The ss's dateCreated is "+ ss.getdateCreated());
    }
    }
    
    class Account{
    private int id=0;
    private double balance=0;
    private double annualInterestRate=0;
    private java.util.Date dateCreated=new java.util.Date();
    public Account(){
    }
    public Account(int newid,int newbalance){
    id=newid;
    balance=newbalance;
    }
    public int getid(){
    return id;
    }
    public double getbalance(){
    return balance;
    }
    public double getannualInterestRate(){
    return annualInterestRate;
    }
    public void setid(int newid){
    id=newid;
    }
    public void setbalance(double newbalance){
    balance=newbalance;
    }
    public void setannualInterestRate(double newannualInterestRate){
    annualInterestRate=newannualInterestRate;
    }
    public double getMonthlyInterest(){
    return (annualInterestRate/12)/100;
    }
    public String getdateCreated(){
    return dateCreated.toString();
    }
    public void withDraw(double draw){
    balance-=draw;
    }
    public void deposit(double draw){
    balance+=draw;
    }
    }

    运行结果:

    JAVA编程练习  账户对象创建(账户名 余额  利息  日期等)
  • 相关阅读:
    向上造型
    Service与Activity通信
    adb报错:no permissions (user in plugdev group; are your udev rules wrong?); see [http://developer.android.com/tools/device.html]
    13-AB Test学习
    1-端到端机器学习项目
    12-数据分析框架
    2-电影推荐案例学习
    11-pyecharts使用Tab不完全代码示例
    22-基于Python构建GRPC服务
    akka练习
  • 原文地址:https://www.cnblogs.com/Kaniso-Vok/p/13756247.html
Copyright © 2020-2023  润新知