{"id":654,"date":"2022-10-04T00:11:11","date_gmt":"2022-10-03T16:11:11","guid":{"rendered":"https:\/\/qaqaq.top\/?p=654"},"modified":"2022-11-27T12:39:57","modified_gmt":"2022-11-27T04:39:57","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%a02%ef%bc%9a%e5%af%b9%e8%b1%a1%e6%95%b0%e7%bb%84","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=654","title":{"rendered":"\u9762\u5411\u5bf9\u8c61(\u4e0a)-\u7efc\u5408\u7ec3\u4e602\uff1a\u5bf9\u8c61\u6570\u7ec4"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P237;\r\n\r\npublic class Account {\r\n\r\n\tprivate double balance;\r\n\t\r\n\tpublic Account(double init_balance) {\r\n\t\t\r\n\t\tthis.balance = init_balance;\r\n\t\t\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\t\/\/\u5b58\u94b1\u64cd\u4f5c\r\n\tpublic void deposit(double amt) {\r\n\t\t\r\n\t\tif(amt > 0) {\r\n\t\t\tbalance += amt;\r\n\t\t\tSystem.out.println(\"\u5b58\u94b1\u6210\u529f\");\r\n\t\t}\r\n\t}\r\n\t\r\n\t\/\/\u53d6\u94b1\u64cd\u4f5c\r\n\tpublic void withdraw(double amt) {\r\n\t\t\r\n\t\tif(balance >= amt) {\r\n\t\t\tbalance -= amt;\r\n\t\t\tSystem.out.println(\"\u53d6\u94b1\u6210\u529f\");\r\n\t\t}else{\r\n\t\t\tSystem.out.println(\"\u4f59\u989d\u4e0d\u8db3\");\r\n\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.P237;\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}\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 acct) {\r\n\t\t\r\n\t\tthis.account = acct;\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.P237;\r\n\r\npublic class Bank {\r\n\t\r\n\tprivate Customer&#91;] customers;\/\/\u5b58\u653e\u591a\u4e2a\u5ba2\u6237\u7684\u6570\u7ec4\r\n\tprivate int numberOfCustomers;\/\/\u8bb0\u5f55\u5ba2\u6237\u7684\u4e2a\u6570\r\n\t\r\n\tpublic Bank() {\r\n\t\t\r\n\t\tcustomers = new Customer&#91;10];\r\n\t}\r\n\t\r\n\t\/\/\u6dfb\u52a0\u5ba2\u6237\r\n\tpublic void addCustomer(String f,String l) {\r\n\t\tCustomer cust = new Customer(f,l);\r\n\/\/\t\tcustomers&#91;numberOfCustomers] = cust;\r\n\/\/\t\tnumberOfCustomers++;\r\n\t\t\/\/\u6216\r\n\t\tcustomers&#91;numberOfCustomers++] = cust;\r\n\t}\r\n\t\r\n\t\/\/\u83b7\u53d6\u5ba2\u6237\u7684\u4e2a\u6570\r\n\tpublic int getNumOfCustomers() {\r\n\t\t\r\n\t\treturn numberOfCustomers;\r\n\t}\r\n\t\r\n\t\/\/\u83b7\u53d6\u6307\u5b9a\u4f4d\u7f6e\u4e0a\u7684\u5ba2\u6237\r\n\tpublic Customer getCustomer(int index) {\r\n\t\t\r\n\/\/\t\treturn customers&#91;index];\/\/\u53ef\u80fd\u62a5\u5f02\u5e38\r\n\t\tif(index >= 0 &amp;&amp; index &lt; numberOfCustomers) {\r\n\t\t\treturn customers&#91;index];\r\n\t\t}\r\n\t\t\r\n\t\treturn null;\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.P237;\r\n\r\npublic class BankTest {\r\n\t\r\n\tpublic static void main(String&#91;] args) {\r\n\t\t\r\n\t\tBank bank = new Bank();\r\n\t\t\r\n\t\tbank.addCustomer(\"Jane\", \"Smith\");\r\n\t\t\r\n\t\t\/\/\u8fde\u7eed\u64cd\u4f5c\r\n\t\tbank.getCustomer(0).setAccount(new Account(2000));\r\n\t\t\r\n\t\tbank.getCustomer(0).getAccount().withdraw(500);\r\n\t\t\r\n\t\tdouble balance = bank.getCustomer(0).getAccount().getBalance();\r\n\t\tSystem.out.println(\"\u5ba2\u6237\uff1a\" + bank.getCustomer(0).getFirstName() + \"\u7684\u8d26\u6237\u4f59\u989d\u4e3a\uff1a\" + balance);\r\n\t\t\r\n\t\tSystem.out.println(\"*************************\");\r\n\t\t\r\n\t\tbank.addCustomer(\"\u4e07\u91cc\", \"\u6768\");\r\n\t\t\r\n\t\tSystem.out.println(\"\u94f6\u884c\u5ba2\u6237\u7684\u4e2a\u6570\u4e3a\uff1a\" + bank.getNumOfCustomers());\r\n\t\t\r\n\t\t\r\n\t\t\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-654","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\/654"}],"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=654"}],"version-history":[{"count":1,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/654\/revisions"}],"predecessor-version":[{"id":655,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/654\/revisions\/655"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}