12.13课堂

学生录入

package Text8;

public class Student {

	
			private String name;
			private int age;
			private int id;
			private String sex;
			
			
			public String getName() {
				return name;
			}
			public void setName(String name) {
				this.name = name;
			}
			public int getAge() {
				return age;
			}
			public void setAge(int age) {
				this.age = age;
			}
			public int getId() {
				return id;
			}
			public void setId(int id) {
				this.id = id;
			}
			public String getSex() {
				return sex;
			}
			public void setSex(String sex) {
				this.sex = sex;
			}
			
			public Student(String name, int age, int id, String sex) {
				super();
				this.name = name;
				this.age = age;
				this.id = id;
				this.sex = sex;
			}
	
			@Override
			public int hashCode() {
				final int prime = 31;
				int result = 1;
				result = prime * result + age;
				result = prime * result + id;
				result = prime * result + ((name == null) ? 0 : name.hashCode());
				result = prime * result + ((sex == null) ? 0 : sex.hashCode());
				return result;
			}
			@Override
			public boolean equals(Object obj) {
				if (this == obj)
					return true;
				if (obj == null)
					return false;
				if (getClass() != obj.getClass())
					return false;
				Student other = (Student) obj;
				if (age != other.age)
					return false;
				if (id != other.id)
					return false;
				if (name == null) {
					if (other.name != null)
						return false;
				} else if (!name.equals(other.name))
					return false;
				if (sex == null) {
					if (other.sex != null)
						return false;
				} else if (!sex.equals(other.sex))
					return false;
				return true;
			}
			
			@Override
			public String toString() {
				return "Student [name=" + name + ", age=" + age + ", id=" + id + ", sex=" + sex + "]";
			}
			public static void main(String[] args) {
				Student stu1 = new Student("辉少",18,10,"男");
				Student stu2 = new Student("辉少",18,10,"女");
				boolean b = stu1.equals(stu2);
				
				System.out.println(stu2.toString());
	}

}

猜你喜欢

转载自blog.csdn.net/weixin_43961593/article/details/85001555
今日推荐