{"id":368,"date":"2022-09-18T12:45:47","date_gmt":"2022-09-18T04:45:47","guid":{"rendered":"https:\/\/qaqaq.top\/?p=368"},"modified":"2022-11-27T12:40:02","modified_gmt":"2022-11-27T04:40:02","slug":"%e9%a1%b9%e7%9b%ae%e4%b8%80-%e5%ae%b6%e5%ba%ad%e6%94%b6%e6%94%af%e8%ae%b0%e8%b4%a6%e8%bd%af%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=368","title":{"rendered":"\u9879\u76ee\u4e00 \u5bb6\u5ead\u6536\u652f\u8bb0\u8d26\u8f6f\u4ef6\u7684\u5b9e\u73b0"},"content":{"rendered":"\n<p>FamilyAccount.java<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\nclass FamilyAccount{\n\n\tpublic static void main(String&#91;] args){\n\n\t\tboolean isFlag = true;\n\t\t\/\/\u7528\u4e8e\u8bb0\u5f55\u7528\u6237\u7684\u6536\u5165\u548c\u652f\u51fa\u7684\u8be6\u60c5\n\t\tString details =  \"\u6536\u652f\\t\u8d26\u6237\u91d1\u989d\\t\u6536\u652f\u91d1\u989d\\t\u8bf4    \u660e\\n\";\n\t\t\/\/\u521d\u59cb\u91d1\u989d\n\t\tint balance = 10000;\n\n\t\twhile(isFlag){\n\n\t\t\tSystem.out.println(\"\\n-----------------\u5bb6\u5ead\u6536\u652f\u8bb0\u8d26\u8f6f\u4ef6-----------------\\n\");\n\t\t\tSystem.out.println(\"                   1 \u6536\u652f\u660e\u7ec6\");\n\t\t\tSystem.out.println(\"                   2 \u767b\u8bb0\u6536\u5165\");\n\t\t\tSystem.out.println(\"                   3 \u767b\u8bb0\u652f\u51fa\");\n\t\t\tSystem.out.println(\"                   4 \u9000    \u51fa\\n\");\n\t\t\tSystem.out.print(\"                   \u8bf7\u9009\u62e9(1-4)\uff1a\");\n\t\t\t\/\/\u83b7\u53d6\u7528\u6237\u7684\u9009\u62e9\uff1a1-4\n\t\t\tchar selection = Utility.readMenuSelection();\n\t\t\tswitch(selection){\n\n\t\t\tcase '1':\n\t\t\t\/\/System.out.println(\"1. \u6536\u652f\u660e\u7ec6\");\n\n\t\t\tSystem.out.println(\"\\n-----------------\u5f53\u524d\u6536\u652f\u660e\u7ec6\u8bb0\u5f55-----------------\");\n\t\t\tSystem.out.println(details);\n\t\t\tSystem.out.println(\"--------------------------------------------------\");\n\t\t\tbreak;\n\t\t\tcase '2':\n\t\t\t\/\/System.out.println(\"2. \u767b\u8bb0\u6536\u5165\");\n\n\t\t\tSystem.out.print(\"\u672c\u6b21\u6536\u5165\u91d1\u989d\uff1a\");\n\t\t\tint addMoney = Utility.readNumber();\n\t\t\tSystem.out.print(\"\u672c\u6b21\u6536\u5165\u8bf4\u660e\uff1a\");\n\t\t\tString addInfo = Utility.readString();\n\n\t\t\t\/\/\u5904\u7406balance\n\t\t\tbalance += addMoney;\n\t\t\t\n\t\t\t\/\/\u5904\u7406details\n\t\t\tdetails += (\"\u6536\u5165\\t\" + balance + \"\\t\\t\" + addMoney + \"\\t\\t\" + addInfo + \"\\n\");\n\n\t\t\tSystem.out.println(\"---------------------\u767b\u8bb0\u5b8c\u6210---------------------\");\n\t\t\tbreak;\n\t\t\tcase '3':\n\t\t\t\/\/System.out.println(\"3. \u767b\u8bb0\u652f\u51fa\");\n\n\t\t\tSystem.out.print(\"\u672c\u6b21\u652f\u51fa\u91d1\u989d\uff1a\");\n\t\t\tint minusMoney = Utility.readNumber();\n\t\t\tSystem.out.print(\"\u672c\u6b21\u652f\u51fa\u8bf4\u660e\uff1a\");\n\t\t\tString minusInfo = Utility.readString();\n\n\t\t\t\/\/\u5904\u7406balance\n\t\t\tif(balance &gt;= minusMoney){\n\t\t\t\tbalance -= minusMoney;\n\t\t\t}else{\n\t\t\t\tSystem.out.println(\"\u652f\u51fa\u8d85\u51fa\u8d26\u6237\u989d\u5ea6\u3002\u652f\u4ed8\u5931\u8d25\");\n\t\t\t}\n\n\t\t\t\/\/\u5904\u7406details\n\t\t\tdetails += (\"\u652f\u51fa\\t\" + balance + \"\\t\\t\" + minusMoney + \"\\t\\t\" + minusInfo + \"\\n\");\n\n\t\t\tSystem.out.println(\"---------------------\u767b\u8bb0\u5b8c\u6210---------------------\");\n\t\t\tbreak;\n\t\t\tcase '4':\n\t\t\t\/\/System.out.println(\"4. \u9000\u51fa\");\n\t\t\tSystem.out.print(\"\u786e\u8ba4\u662f\u5426\u9000\u51fa(Y\/N)\uff1a\");\n\t\t\tchar isExit = Utility.readConfirmSelection();\n\t\t\t\tif(isExit == 'Y'){\n\t\t\t\t\tisFlag = false;\n\t\t\t\t}\n\n\t\t\t\t\/\/break;\n\n\t\t\t}\n\n\t\t}\n\t}\n}<\/code><\/pre>\n\n\n\n<p>Utility.java<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Scanner;\n\/**\nUtility\u5de5\u5177\u7c7b\uff1a\n\u5c06\u4e0d\u540c\u7684\u529f\u80fd\u5c01\u88c5\u4e3a\u65b9\u6cd5\uff0c\u5c31\u662f\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7\u8c03\u7528\u65b9\u6cd5\u4f7f\u7528\u5b83\u7684\u529f\u80fd\uff0c\u800c\u65e0\u9700\u8003\u8651\u5177\u4f53\u7684\u529f\u80fd\u5b9e\u73b0\u7ec6\u8282\u3002\n*\/\npublic class Utility {\n    private static Scanner scanner = new Scanner(System.in);\n    \/**\n\t\u7528\u4e8e\u754c\u9762\u83dc\u5355\u7684\u9009\u62e9\u3002\u8be5\u65b9\u6cd5\u8bfb\u53d6\u952e\u76d8\uff0c\u5982\u679c\u7528\u6237\u952e\u5165\u20191\u2019-\u20194\u2019\u4e2d\u7684\u4efb\u610f\u5b57\u7b26\uff0c\u5219\u65b9\u6cd5\u8fd4\u56de\u3002\u8fd4\u56de\u503c\u4e3a\u7528\u6237\u952e\u5165\u5b57\u7b26\u3002\n\t*\/\n\tpublic static char readMenuSelection() {\n        char c;\n        for (; ; ) {\n            String str = readKeyBoard(1);\n            c = str.charAt(0);\n            if (c != '1' &amp;&amp; c != '2' &amp;&amp; c != '3' &amp;&amp; c != '4') {\n                System.out.print(\"\u9009\u62e9\u9519\u8bef\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\uff1a\");\n            } else break;\n        }\n        return c;\n    }\n\t\/**\n\t\u7528\u4e8e\u6536\u5165\u548c\u652f\u51fa\u91d1\u989d\u7684\u8f93\u5165\u3002\u8be5\u65b9\u6cd5\u4ece\u952e\u76d8\u8bfb\u53d6\u4e00\u4e2a\u4e0d\u8d85\u8fc74\u4f4d\u957f\u5ea6\u7684\u6574\u6570\uff0c\u5e76\u5c06\u5176\u4f5c\u4e3a\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u3002\n\t*\/\n    public static int readNumber() {\n        int n;\n        for (; ; ) {\n            String str = readKeyBoard(4);\n            try {\n                n = Integer.parseInt(str);\n                break;\n            } catch (NumberFormatException e) {\n                System.out.print(\"\u6570\u5b57\u8f93\u5165\u9519\u8bef\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\uff1a\");\n            }\n        }\n        return n;\n    }\n\t\/**\n\t\u7528\u4e8e\u6536\u5165\u548c\u652f\u51fa\u8bf4\u660e\u7684\u8f93\u5165\u3002\u8be5\u65b9\u6cd5\u4ece\u952e\u76d8\u8bfb\u53d6\u4e00\u4e2a\u4e0d\u8d85\u8fc78\u4f4d\u957f\u5ea6\u7684\u5b57\u7b26\u4e32\uff0c\u5e76\u5c06\u5176\u4f5c\u4e3a\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u3002\n\t*\/\n    public static String readString() {\n        String str = readKeyBoard(8);\n        return str;\n    }\n\t\n\t\/**\n\t\u7528\u4e8e\u786e\u8ba4\u9009\u62e9\u7684\u8f93\u5165\u3002\u8be5\u65b9\u6cd5\u4ece\u952e\u76d8\u8bfb\u53d6\u2018Y\u2019\u6216\u2019N\u2019\uff0c\u5e76\u5c06\u5176\u4f5c\u4e3a\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u3002\n\t*\/\n    public static char readConfirmSelection() {\n        char c;\n        for (; ; ) {\n            String str = readKeyBoard(1).toUpperCase();\n            c = str.charAt(0);\n            if (c == 'Y' || c == 'N') {\n                break;\n            } else {\n                System.out.print(\"\u9009\u62e9\u9519\u8bef\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\uff1a\");\n            }\n        }\n        return c;\n    }\n\t\n\t\n    private static String readKeyBoard(int limit) {\n        String line = \"\";\n\n        while (scanner.hasNext()) {\n            line = scanner.nextLine();\n            if (line.length() &lt; 1 || line.length() &gt; limit) {\n                System.out.print(\"\u8f93\u5165\u957f\u5ea6\uff08\u4e0d\u5927\u4e8e\" + limit + \"\uff09\u9519\u8bef\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\uff1a\");\n                continue;\n            }\n            break;\n        }\n\n        return line;\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>FamilyAccount.java Utility.java<\/p>\n","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-368","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\/368"}],"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=368"}],"version-history":[{"count":3,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/368\/revisions"}],"predecessor-version":[{"id":508,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/368\/revisions\/508"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}