- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
* * Object?提供的?hashCode()?的缺省实施通过将对象的内存地址对映于一个整数值来生成。 As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.) * public class AccountTester { public static void main(String args[]) { BankAccount anAccount; anAccount = new BankAccount(ZhangLi, 100023,0); anAccount.setBalance(anAccount.getBalance() + 100); System.out.println(anAccount); System.out.println(); anAccount = new BankAccount(WangFang, 100024,0); System.out.println(anAccount); anAccount.deposit(225.67f); anAccount.deposit(300.00f); System.out.println(anAccount); anAccount.withdraw(400.17f); System.out.println(anAccount); } } 应用举例 2.3.3 声明存取款方法 ——修改AccountTester.java * 测试结果 Account #100023 with balance $100.0 Account #100024 with balance $0.0 Account #100024 with balance $525.67 Account #100024 with balance $125.49997 应用举例 2.3.3 声明存取款方法 ——测试结果 * DecimalFormat类 在java.text包中 在toString()方法中使用DecimalFormat类的实例方法format对数据进行格式化 修改后的toString()方法如下 应用举例 2.3.4 使用DecimalFormat类 public String toString() { return(Account # + accountNumber + with balance + new java.text.DecimalFormat($0.00).format(balance)); } * 对BankAccount类重新进行编译,再运行BankTester类,运行结果如下 Account #100023 with balance $100.00 Account #100024 with balance $0.00 Account #100024 with balance $525.67 Account #100024 with balance $125.50 应用举例 2.3.4 使用DecimalFormat类 ——测试结果 * 声明类方法返回特殊的BankAccount实例,作用是生成特定的几种账号样例 Example1()方法 应用举例 2.3.5 声明类方法生成特殊的实例 public static BankAccount example1() { BankAccount ba = new BankAccount(); ba.setOwnerName(LiHong); ba.setAccountNumber(554000); ba.deposit(1000);
您可能关注的文档
最近下载
- 锅炉本体检修工职业技能鉴定高级工试题.docx VIP
- 初中数学重点知识点梳理汇总.docx VIP
- [中国青铜器]01.第一章 概论.pdf VIP
- 德国探亲签邀请函中德文对照.docx
- 2024山西太原市古交市招聘劳动保障工作站和社区低保工作站人员笔试历年典型考题及考点剖析附答案带详解.docx VIP
- 2025年高等教育自学考试马克思主义基本原理概论真题及模拟试题汇编.doc VIP
- it审计的组织与实施(培训课件).ppt VIP
- 2025社区两保人员考试真题及答案.doc VIP
- 《春江花月夜》教学设计及课堂镜头.doc VIP
- 肿瘤多学科综合治疗模式与个体化治疗研究进展.docx VIP
文档评论(0)