admin管理员组文章数量:1648371
类与对象,作为一个面向对象的程序员,对象和类是经常会碰到的。只有什么是对象,各位,敢说“万物皆对象”吗?类是同一类型的对象的合约,模板或蓝本。(其实,我本人不喜欢这些咬文嚼字的东东),不多说,直接代码解释。
package com.exercise; import java.util.Date; /** * 账户类 Account * Created by mark on 2016/8/5. */ public class Account { private int id = 0; private double balance = 0.0; private double annualInterestRate = 0.0;// 当前利率 private Date dateCreated;// 账户的开户日期 public Account() { dateCreated = new Date(); } public Account(int id, double balance) { this.id = id; this.balance = balance; dateCreated = new Date(); } public int getId() { return id; } public void setId(int id) { this.id = id; } public double getBalance() { return balance; } public void setBalance(double balance) { this.balance = balance; } public double getAnnualInterestRate() { return annualInterestRate; } public void setAnnualInterestRate(double annualInterestRate) { this.annualInterestRate = annualInterestRate; } public Date getDateCreated() { return dateCreated; } public double getMonthlyInterestRate() { return balance * (annualInterestRate / 1200); } public void withDraw(double account) { balance -= account; } public void deposit(double account) { balance += account; } public static void main(String[] args) { Account account = new Account(1122, 20000); account.setAnnualInterestRate(4.5); account.withDraw(2500); account.deposit(3000); System.out.println("余额为: " + account.getBalance()); System.out.println("月利息为: " + account.getMonthlyInterestRate()); System.out.println("账户的开户日期为: " + account.getDateCreated()); } }
版权声明:本文标题:账户类 Account 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1729497966a1203135.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论