创建一个People类,年龄,工资,性别三个属性
定义一个方法叫做找对象,找对象方法传过来一个人,
首先如果性别相同,就输出"不是同性恋"
如果对方是男的,年龄小于28,工资大于10000 就输出"xx"
如果年龄太大就输出 " 太老了 "
如果工资太低就输出 " 不合适 "
如果对方是女的,年龄比自己小,工资大于 3000 就输出 " 结婚 "
如果年龄太大就输出 " 我不找比自己大的女性 "
如果工资太少就输出 " 还需努力 "
package TodayHw;
public class People {
private int age;
private double salary;
private boolean gender; // false = 女 true = 男
// 找对象
public void getMarray(People people) {
// 判断 p1的性别 和 p2的性别
if (this.isGender() == people.isGender()) {
System.out.println("同性恋???");
return;
}
// 判断本人是男女
// 本人男
// 女不能大于自己的年龄
if (this.isGender()) {
if (this.getAge() < people.getAge()) {
System.out.println("女方年龄不能大于男方的年龄");
return;
} else {
//年龄满足了,判断工资的水平,女方工资大于3000即可
if (people.getSalary() >= 3000) {
System.out.println("民政局见");
} else {
System.out.println("女方工资太低了");
}
}
} else {
// 本人女
// 男不能大于28
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 = age;
this.salary = salary;
this.gender = gender;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public boolean isGender() {
return gender;
}
public void setGender(boolean gender) {
this.gender = gender;
}
}
package TodayHw;
public class TestPeople {
public static void main(String[] args) {
People people1 = new People(27, 2000, true);
People people2 = new People(29, 10001, false);
people1.getMarray(people2);
}
}