- 创建一个People类型,有年龄、工资、性别三个属性。
- 定义一个方法叫做找对象,找对象方法传过来一个人;
- 首先如果性别相同,就输出“我不是同性恋”,
- 如果对方是男的,年龄小于28,工资大于10000,就输出"我们结婚吧",
- 如果年龄太大就输出“太老了,我们不合适!”,
- 如果钱太少了就输出“小伙还需在努力,我们不合适”;
- 如果对方是女的,年龄比自己小,工资大于3000,就输出“我们结婚吧”,
- 如果年龄太大就输出“我不找比自己大的女性”,
- 如果工资太少就输出“女士还需再努力,我们不合适”。
public class People {
//属性私有化
private int age;
private double salary;
private char gender;
/**
* 找对象方法
*
* @param people
*/
public void find_friend(People people) {
//people就是你要找的对象
//性别相同 你(调用者) 和传入的对象性别相同
if (people.getGender() == this.gender) {
//this.gender this.可以省略不写
System.out.println("不是同性恋");
}
if (people.getGender() == '男' && people.getGender() != gender) {
if (people.getAge() < 28 && people.getSalary() >= 10000) {
System.out.println("我们结婚吧");
}
if (people.getAge() > 28) {
System.out.println("我们不合适");
}
if (people.getSalary() < 10000) {
System.out.println("小伙还需在努力,我们不合适");
}
}
if (people.getGender() == '女' && people.getGender() != gender) {
if (age >= people.getAge() && people.getSalary() >= 3000) {
System.out.println("我们结婚吧");
}
if (age < people.getAge()) {
System.out.println("我不找比自己大的的女性");
}
if (people.getSalary() < 3000) {
System.out.println("女士还需再努把力,我们不合适");
}
}
}
public People() {
}
public People(int age, double salary, char 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 char getGender() {
return gender;
}
public void setGender(char gender) {
if (gender == '男' || gender == '女') {
this.gender = gender;
} else {
this.gender = '男';
}
}
}