In: Computer Science
public class Person {
private String name;
public Person()
{
name = "No name yet";
}
public Person(String initialName)
{
name = initialName;
}
public void setName(String newName)
{
name = newName;
}
public String getName()
{
return name;
}
public void writeOutput()
{
System.out.println("Name: " + name);
}
public boolean hasSameName(Person otherPerson)
{
return this.name.equalsIgnoreCase(otherPerson.name);
}
}
2- Write a Program Patient. Java
Class that extends Person to include
Social security
Gender
Appropriate construtors, accessors, and mutators.
WriteOutput method
an equals method to test if all parameters for two patients are equal.
a program to test patient
class Person {
private String name;
public Person()
{
name = "No name yet";
}
public Person(String initialName)
{
name = initialName;
}
public void setName(String newName)
{
name = newName;
}
public String getName()
{
return name;
}
public void writeOutput()
{
System.out.println("Name: " + name);
}
public boolean hasSameName(Person otherPerson)
{
return this.name.equalsIgnoreCase(otherPerson.name);
}
}
class Patient extends Person{
private String ssn;
private String gender;
public Patient(String name,String aSsn, String
aGender) {
super(name);
ssn = aSsn;
gender = aGender;
}
public String getSsn() {
return ssn;
}
public String getGender() {
return gender;
}
public void setSsn(String aSsn) {
ssn = aSsn;
}
public void setGender(String aGender) {
gender = aGender;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((gender
== null) ? 0 : gender.hashCode());
result = prime * result + ((ssn ==
null) ? 0 : ssn.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;
Patient other = (Patient)
obj;
if (gender == null) {
if (other.gender
!= null)
return false;
} else if
(!gender.equals(other.gender))
return
false;
if (ssn == null) {
if (other.ssn !=
null)
return false;
} else if
(!ssn.equals(other.ssn))
return
false;
return true;
}
public void writeOutput() {
super.writeOutput();
System.out.println("SSN:
"+ssn+"\nGender: "+gender);
}
}
public class TestPatient {
public static void main(String[] args) {
Patient p = new Patient("Uday",
"male","444-122-121");
p.writeOutput();
}
}
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me