- 11th Nov 2022
- 03:30 am
- Admin
Java Programming Homework Help - Solution for Public Class Person Task
public class Person {
// Data fields
private String name;
private int age;
private boolean gender;
// Methods
Person(String a, int b, boolean c){
name = a;
age = b;
gender = c;
}
public String getName() {
return name;
}
public void changeName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public String getGender() {
if(gender)
return "male";
return "female";
}
public String toString() {
return name+", age: "+age+", Gender: "+getGender();
}
public boolean equals(Object o) {
if(o==this)
return true;
Student s = (Student)o;
if(s.getAge()!=this.age)
return false;
if(s.getName()!=this.name)
return false;
if(s.getGender()!=this.getGender())
return false;
return true;
}
}