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

java编写账户(余额,月利息,开户日期)

时间:2019-04-28 23:13:26      阅读:444      评论:0      收藏:0      [点我收藏+]

标签:string   dep   epo   void   java   port   vat   账户   hdr   

import java.util.Date; public class TestAccount //测试类 { public static void main(String[] args) { Account c1=new Account(1122,20000); c1.setAnnualInterestRate(4.5/100); c1.withDraw(2500); c1.deposit(3000); System.out.println("余额为"+c1.getBalance()); System.out.println("月利息为"+c1.getMonthlyInterest()+‘%‘); System.out.println("开户日期是"+c1.getDateCreated().toString()); } } class Account //功能类 { private int id; private double balance; private double annualInterestRate; 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; } }

java编写账户(余额,月利息,开户日期)

标签:string   dep   epo   void   java   port   vat   账户   hdr   

原文地址:https://blog.51cto.com/14233078/2386340

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