作者:pan2502851807 | 来源:互联网 | 2024-12-14 18:42
创建一个People类,年龄,工资,性别三个属性定义一个方法叫做找对象,找对象方法传过来一个人,首先如果性别相同,就输出不是同性恋如果对方是男的,年龄小于28,工资大于1000
创建一个People类,年龄,工资,性别三个属性 定义一个方法叫做找对象,找对象方法传过来一个人, 首先如果性别相同,就输出"不是同性恋" 如果对方是男的,年龄小于28,工资大于10000 就输出"xx" 如果年龄太大就输出 " 太老了 " 如果工资太低就输出 " 不合适 "
如果对方是女的,年龄比自己小,工资大于 3000 就输出 " 结婚 " 如果年龄太大就输出 " 我不找比自己大的女性 " 如果工资太少就输出 " 还需努力 "
package TodayHw; public class People { private int age; private double salary; private boolean gender; public void getMarray ( People people) { if ( this . isGender ( ) &#61;&#61; people. isGender ( ) ) { System. out. println ( "同性恋???" ) ; return ; } if ( this . isGender ( ) ) { if ( this . getAge ( ) < people. getAge ( ) ) { System. out. println ( "女方年龄不能大于男方的年龄" ) ; return ; } else { if ( people. getSalary ( ) >&#61; 3000 ) { System. out. println ( "民政局见" ) ; } else { System. out. println ( "女方工资太低了" ) ; } } } else { if ( people. getAge ( ) > 28 ) { System. out. println ( "女方不能接受男方28岁" ) ; return ; } else { if ( people. getSalary ( ) < 10000 ) { System. out. println ( "女方不能接受男方工资低于1W" ) ; return ; } else { System. out. println ( "民政局见" ) ; } } } } public People ( ) { } public People ( int age, double salary, boolean gender) { this . age &#61; age; this . salary &#61; salary; this . gender &#61; gender; } public int getAge ( ) { return age; } public void setAge ( int age) { this . age &#61; age; } public double getSalary ( ) { return salary; } public void setSalary ( double salary) { this . salary &#61; salary; } public boolean isGender ( ) { return gender; } public void setGender ( boolean gender) { this . gender &#61; gender; } }
package TodayHw; public class TestPeople { public static void main ( String[ ] args) { People people1 &#61; new People ( 27 , 2000 , true ) ; People people2 &#61; new People ( 29 , 10001 , false ) ; people1. getMarray ( people2) ; } }