那些年,我写过的面向对象 (Java)
来源:互联网 发布:外国人评论中国 知乎 编辑:程序博客网 时间:2024/06/10 06:34
程序1.
//时间:2013.11.07//功能:创建账户Account 类 并且把它的信息输出出来public class AccountShow {public static void main (String[] args) {Account account = new Account(1122, 20000); //创建一个对象,ID为1122,余额20000Account.setAnnualInterestRate(4.5);//设置年利率 4.5%account.withdraw(2500);//取款 2500account.deposit(3000);//存款3000System.out.println("Balance is " + account.getBalance()); //打印余额System.out.println("Monthly interest is " +//打印月利率account.getMonthlyInterest());System.out.println("This account was created at " +//打印开户日期account.getDateCreated());}}class Account {//创建Account类private int id;//创建Account的成员及方法private double balance;private static double annualInterestRate;private java.util.Date dateCreated;public Account() { //创建无参构造方法dateCreated = new java.util.Date();}public Account(int newId, double newBalance) { //创建有id,余额 的构造方法id = newId;balance = newBalance;dateCreated = new java.util.Date();}public int getId() {//创建getId()方法return this.id;}public double getBalance() {//创建getBalance()方法return balance;}public static double getAnnualInterestRate() {//创建getAnnualInterestRate()方法return annualInterestRate;}public void setId(int newId) { //创建setId(int newId)方法id = newId;}public void setBalance(double newBalance) {//创建setBalance()方法balance = newBalance;}//创建setAnnualInterestRate(double newAnnualInterestRate)方法public static void setAnnualInterestRate(double newAnnualInterestRate) {annualInterestRate = newAnnualInterestRate;}public double getMonthlyInterest() {//创建getMonthlyInterest()方法return balance * (annualInterestRate / 1200);}public java.util.Date getDateCreated() {//创建getDateCreated() 方法return dateCreated;}public void withdraw(double amount) {//创建withdraw(double amount)方法balance -= amount;}public void deposit(double amount) {//创建deposit(double amount)方法balance += amount;}}
- 那些年,我写过的面向对象 (Java)
- 那些年我写过的代码
- 那些年我踩过的坑——Java
- 【我的大学】那些本科时候写过的代码
- 那些年,写过的代码
- 那些年写过的C语言
- 那些年写过的贪吃蛇
- 那些年写过的有趣注释
- 那些年我们写过的爬虫
- 那些年写过的选择器
- 我的第一个项目——说说那些年我们一起写过的代码
- 那些年我准备过的cfa
- 那些年我追过的android
- 那些年我追过的android
- 那些年我追过的android
- 那些年我追过的android
- 那些年,我用过的虚拟主机
- 那些年我踩过的坑
- ie8下打开无菜单栏,无工具栏页面JS
- Page工具类
- 玩转robots协议
- Qt 程序显示不出加载的图片
- IOS开发证书申请流程和给他人电脑授权
- 那些年,我写过的面向对象 (Java)
- PHP学习#Yii扩展第三方框架的使用
- Extjs4---treepanel+struts2异步加载
- 编译MT7620n NFS文件系统
- 实战Linux Bluetooth编程(五) Socket与Bluetooth
- MFC 非模态对话框覆盖主对话框销毁问题
- Xcode 4 missing file
- js 倒计时
- 关于Oracle11gR2的相关配置问题