{"id":641,"date":"2022-10-02T12:29:22","date_gmt":"2022-10-02T04:29:22","guid":{"rendered":"https:\/\/qaqaq.top\/?p=641"},"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-this%e7%bb%83%e4%b9%a0%ef%bc%9aboy%e5%92%8cgirl","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=641","title":{"rendered":"\u9762\u5411\u5bf9\u8c61(\u4e0a)-this\u7ec3\u4e60\uff1aBoy\u548cGirl"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P235;\r\n\r\npublic class Boy {\r\n\r\n\tprivate String name;\r\n\tprivate int age;\r\n\t\r\n\tpublic Boy() {\r\n\t\t\r\n\t}\r\n\t\r\n\tpublic Boy(String name) {\r\n\t\tthis.name = name;\r\n\t}\r\n\t\r\n\tpublic Boy(String name, int age) {\r\n\t\tthis.name = name;\r\n\t\tthis.age = age;\r\n\t}\r\n\r\n\tpublic void setName(String name) {\r\n\t\tthis.name = name;\r\n\t}\r\n\t\r\n\tpublic String getName() {\r\n\t\treturn name;\r\n\t}\r\n\t\r\n\tpublic void setAge(int age) {\r\n\t\tthis.age = age;\r\n\t}\r\n\t\r\n\tpublic int getAge() {\r\n\t\treturn age;\r\n\t}\r\n\t\r\n\tpublic void marry(Girl girl) {\r\n\t\tSystem.out.println(\"\u6211\u60f3\u5a36\" + girl.getName());\r\n\t}\r\n\t\r\n\tpublic void shout() {\r\n\t\tif(this.age >= 22) {\r\n\t\t\tSystem.out.println(\"\u4f60\u53ef\u4ee5\u53bb\u5408\u6cd5\u767b\u8bb0\u7ed3\u5a5a\u4e86\uff01\");\r\n\t\t}else {\r\n\t\t\tSystem.out.println(\"\u5148\u591a\u8c08\u8c08\u604b\u7231~~\");\r\n\t\t}\r\n\t}\r\n\t\r\n}\r\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P235;\r\n\r\npublic class Girl {\r\n\t\r\n\tprivate String name;\r\n\tprivate int age;\r\n\t\r\n\tpublic Girl() {\r\n\t\t\r\n\t}\r\n\t\r\n\tpublic Girl(String name, int age) {\r\n\t\tthis.name = name;\r\n\t\tthis.age = age;\r\n\t}\r\n\t\r\n\tpublic String getName() {\r\n\t\treturn name;\r\n\t}\r\n\t\r\n\tpublic void setName(String name) {\r\n\t\tthis.name = name;\r\n\t}\r\n\t\r\n\tpublic void marry(Boy boy) {\r\n\t\tSystem.out.println(\"\u6211\u60f3\u5ac1\u7ed9\" + boy.getName());\r\n\t\tboy.marry(this);\r\n\t}\r\n\t\r\n\t\/**\r\n\t * \r\n\t* @Description \u6bd4\u8f83\u4e24\u4e2a\u5bf9\u8c61\u7684\u5927\u5c0f\r\n\t* @author RichieZhang\r\n\t* @date 2022\u5e7410\u67082\u65e5\u4e0a\u534811:59:03\r\n\t* @param girl\r\n\t* @return\t\u6b63\u6570\uff1a\u5f53\u524d\u5bf9\u8c61\u5927\uff1b\u8d1f\u6570\uff1a\u5f53\u524d\u5bf9\u8c61\u5c0f\uff1b0\uff1a\u5f53\u524d\u5bf9\u8c61\u4e0e\u5f62\u53c2\u5bf9\u8c61\u76f8\u7b49\r\n\t *\/\r\n\tpublic int compare(Girl girl) {\r\n\/\/\t\tif(this.age > girl.age) {\r\n\/\/\t\t\treturn 1;\r\n\/\/\t\t}else if(this.age &lt; girl.age) {\r\n\/\/\t\t\treturn -1;\r\n\/\/\t\t}else {\r\n\/\/\t\t\treturn 0;\r\n\/\/\t\t}\r\n\t\t\r\n\t\treturn this.age - girl.age;\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.P235;\r\n\r\npublic class BoyGirlTest {\r\n\t\r\n\tpublic static void main(String&#91;] args) {\r\n\t\t\r\n\t\tBoy boy = new Boy(\"\u7f57\u5bc6\u6b27\",21);\r\n\t\tboy.shout();\r\n\t\t\r\n\t\tGirl girl = new Girl(\"\u6731\u4e3d\u53f6\", 18);\r\n\t\tgirl.marry(boy);\r\n\t\t\r\n\t\tGirl girl1 = new Girl(\"\u795d\u82f1\u53f0\",19);\r\n\t\tint compare = girl.compare(girl1);\r\n\t\tif(compare > 0) {\r\n\t\t\tSystem.out.println(girl.getName() + \"\u5927\");\r\n\t\t}else if(compare &lt; 0){\r\n\t\t\tSystem.out.println(girl1.getName() + \"\u5927\");\r\n\t\t}else {\r\n\t\t\tSystem.out.println(\"\u4e00\u6837\u5927\");\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-641","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\/641"}],"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=641"}],"version-history":[{"count":1,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/641\/revisions"}],"predecessor-version":[{"id":642,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/641\/revisions\/642"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=641"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=641"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}