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编程练习  账户对象创建(账户名 余额  利息  日期等)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值