0

I am losing my mind trying to compare two objects with one another, for example:

System.out.println("Equals? " + bob.equals(alice));

Which would return true if both objects contain the same "PIN" and familyNumber" . Issue being I have no idea how to compare the two values at the same time . My current attempt is below, and beneath that is the code being used

 public boolean equals(Patient patientTwo)  //i hate this
 {
   if((getHealthID()).equals.patientTwo.getHealthID())
   {
     if((getPIN) == (patientTwo.getPIN))
     {
      return true;
     }
      else return false;
   }
   else return false;
 }
 public Patient()
 {
  age = 0;
  name = "no_name";
  patientHealthID = patientHealthID;  //NEEDS WORK - GIVEN identical VALUE UNTIL SOLUTION FOUND
  vaccineStatus = false;  //Possibly unnecessary
    }
 
 
 public Patient(String name, int age, HealthID newHealthID)
 {
  this.age = age;
  this.name = name;
  patientHealthID = newHealthID;  //NEEDS WORK
  vaccineStatus = false;
 }
public HealthID() 
 {
  familyNumber = nextFamilyNumber;
  PIN = nextPIN;
  
  nextFamilyNumber++;  //MAY HAVE TO REMOVE
  nextPIN++;
    }
 
 
 public HealthID(int familyNumber)
 {
  this.familyNumber = familyNumber;  //UNSURE IF CORRECT
  PIN = nextPIN;
  
  nextPIN++;
 }
ThePyroGod
  • 13
  • 2
  • you should learn about overriding equals and hashcode. – Natsu Feb 24 '21 at 20:37
  • Hi & Welcome! Best learn & use: https://github.com/apache/commons-lang/blob/master/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java as https://github.com/apache/commons-lang/blob/master/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java – xerx593 Feb 24 '21 at 20:43
  • (A) Besides overriding `equals` & `hashCode`, you may want to learn about [`Comparator`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Comparator.html). (B) Work through the [*Java Tutorials*](https://docs.oracle.com/javase/tutorial/) by Oracle, free of charge, to learn the basics of Java programming. – Basil Bourque Feb 24 '21 at 20:50

0 Answers0