码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2019-04-29 19:21:00      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:dde   代码   对象   blog   image   str   count()   set   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编程练习 账户对象创建(账户名 余额 利息 日期等)

标签:dde   代码   对象   blog   image   str   count()   set   java   

原文地址:https://blog.51cto.com/14232799/2386815

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!