{"id":649,"date":"2022-10-04T00:07:35","date_gmt":"2022-10-03T16:07:35","guid":{"rendered":"https:\/\/qaqaq.top\/?p=649"},"modified":"2022-11-27T12:39:58","modified_gmt":"2022-11-27T04:39:58","slug":"%e9%9d%a2%e5%90%91%e5%af%b9%e8%b1%a1%e4%b8%8a-%e7%bb%bc%e5%90%88%e7%bb%83%e4%b9%a01%ef%bc%9aaccount%e5%92%8ccustomer","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=649","title":{"rendered":"\u9762\u5411\u5bf9\u8c61(\u4e0a)-\u7efc\u5408\u7ec3\u4e601\uff1aAccount\u548cCustomer"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P236;\r\n\r\npublic class Account {\r\n\r\n\tprivate int id;\/\/\u8d26\u53f7\r\n\tprivate double balance;\/\/\u4f59\u989d\r\n\tprivate double annuallnterestRate;\/\/\u5e74\u5229\u7387\r\n\t\r\n\tpublic Account(int id, double balance, double annuallnterestRate) {\r\n\t\t\r\n\t\tthis.id = id;\r\n\t\tthis.balance = balance;\r\n\t\tthis.annuallnterestRate = annuallnterestRate;\r\n\t}\r\n\t\r\n\tpublic int getId() {\r\n\t\t\r\n\t\treturn id;\r\n\t}\r\n\t\r\n\tpublic double getBalance() {\r\n\t\t\r\n\t\treturn balance;\r\n\t}\r\n\t\r\n\tpublic double getAnnuallnterestRate() {\r\n\t\t\r\n\t\treturn annuallnterestRate;\r\n\t}\r\n\t\r\n\tpublic void setId(int id) {\r\n\t\t\r\n\t\tthis.id = id;\r\n\t}\r\n\t\r\n\tpublic void setBalance(double balance) {\r\n\t\t\r\n\t\tthis.balance = balance;\r\n\t}\r\n\t\r\n\tpublic void setAnnuallnterestRate(double annuallnterestRate) {\r\n\t\tthis.annuallnterestRate = annuallnterestRate;\r\n\t}\r\n\t\r\n\t\/\/\u5728\u63d0\u6b3e\u65b9\u6cd5withdraw\u4e2d\uff0c\u9700\u8981\u5224\u65ad\u7528\u6237\u4f59\u989d\u662f\u5426\u80fd\u591f\u6ee1\u8db3\u63d0\u6b3e\u6570\u989d\u7684\u8981\u6c42\uff0c\u5982\u679c\u4e0d\u80fd\uff0c\u5e94\u7ed9\u51fa\u63d0\u793a\u3002\r\n\tpublic void withdraw(double amount) {\t\/\/\u53d6\u94b1\r\n\t\t\r\n\t\tif(balance &lt; amount) {\r\n\t\t\t\r\n\t\t\tSystem.out.println(\"\u4f59\u989d\u4e0d\u8db3\uff0c\u53d6\u6b3e\u5931\u8d25\");\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\tbalance -= amount;\r\n\t\tSystem.out.println(\"\u6210\u529f\u53d6\u51fa\uff1a\" + amount);\r\n\t\t\r\n\t}\r\n\r\n\tpublic void deposit(double amount) {\t\/\/\u5b58\u94b1\r\n\t\t\r\n\t\tif(amount > 0) {\r\n\t\t\t\r\n\t\t\tbalance += amount;\r\n\t\t\tSystem.out.println(\"\u6210\u529f\u5b58\u5165\uff1a\" + amount);\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n}\r\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P236;\r\n\r\npublic class Customer {\r\n\t\r\n\tprivate String firstName;\r\n\tprivate String lastName;\r\n\tprivate Account account;\r\n\t\r\n\tpublic Customer(String f,String l) {\r\n\t\t\r\n\t\tthis.firstName = f;\r\n\t\tthis.lastName = l;\r\n\t\t\r\n\t}\r\n\t\r\n\tpublic String getFirstName() {\r\n\t\t\r\n\t\treturn firstName;\r\n\t}\r\n\t\r\n\tpublic String getLastName() {\r\n\t\t\r\n\t\treturn lastName;\r\n\t}\r\n\t\r\n\tpublic Account getAccount() {\r\n\t\t\r\n\t\treturn account;\r\n\t}\r\n\t\r\n\tpublic void setAccount(Account account) {\r\n\t\t\r\n\t\tthis.account = account;\r\n\t}\r\n\r\n}\r\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P236;\r\n\/*\r\n * \t\u5199\u4e00\u4e2a\u6d4b\u8bd5\u7a0b\u5e8f\u3002\r\n\t\uff081\uff09\u521b\u5efa\u4e00\u4e2aCustomer\uff0c\u540d\u5b57\u53ebJane Smith,\r\n\t\u4ed6\u6709\u4e00\u4e2a\u8d26\u53f7\u4e3a1000\uff0c\u4f59\u989d\u4e3a2000\u5143\uff0c\u5e74\u5229\u7387\u4e3a1.23\uff05\u7684\u8d26\u6237\u3002\r\n\t\uff082\uff09\u5bf9Jane Smith\u64cd\u4f5c\u3002\r\n\t\u5b58\u5165100\u5143\uff0c\u518d\u53d6\u51fa960\u5143\u3002\u518d\u53d6\u51fa2000\u5143\u3002\r\n\t\u6253\u5370\u51faJane Smith\u7684\u57fa\u672c\u4fe1\u606f\r\n\t\u6210\u529f\u5b58\u5165\uff1a100.0\r\n\t\u6210\u529f\u53d6\u51fa\uff1a960.0\r\n\t\u4f59\u989d\u4e0d\u8db3\uff0c\u53d6\u6b3e\u5931\u8d25\r\n\tCustomer &#91;Smith, Jane] has a account: id is 1000, annualInterestRate is 1.23\uff05, balance is 1140.0\r\n * \r\n * \r\n *\/\r\npublic class CustomerTest {\r\n\t\r\n\tpublic static void main(String&#91;] args) {\r\n\t\t\r\n\t\tCustomer cust = new Customer(\"Jane\", \"Smith\");\r\n\t\t\r\n\t\tAccount acct = new Account(1000, 2000, 0.0123);\r\n\t\t\r\n\t\tcust.setAccount(acct);\r\n\t\t\r\n\t\tcust.getAccount().deposit(100);\r\n\t\tcust.getAccount().withdraw(960);\r\n\t\tcust.getAccount().withdraw(2000);\r\n\t\t\r\n\t\tSystem.out.println(\"Customer&#91;\" + cust.getLastName() + \",\" + cust.getFirstName() + \r\n\t\t\t\t\"] has a account: id is \" + cust.getAccount().getId() + \",\" + \"annualInterestRate is \" + \r\n\t\t\t\tcust.getAccount().getAnnuallnterestRate() * 100 + \"%,balance is \" + cust.getAccount().getBalance());\r\n\t}\r\n\r\n}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[46],"class_list":["post-649","post","type-post","status-publish","format-standard","hentry","category-java-code","tag-java"],"_links":{"self":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/649"}],"collection":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=649"}],"version-history":[{"count":1,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/649\/revisions"}],"predecessor-version":[{"id":650,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/649\/revisions\/650"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=649"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=649"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=649"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}