Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

l2) in java Suppose you had the following class Quest2 defined. Further assume t

ID: 3580795 • Letter: L

Question

l2) in java Suppose you had the following class Quest2 defined. Further assume that you wished to override thepublic boolean equals( Object obj ) method so that two objects of the class can be compared to determine if they are equal or not. We will define two Quest2 objects to be equal if their name fields hold the same String value and their val fields hold the same integer value and age fields are also the same.The other fields do not impact equivalence. Write the overriding equals method below.

public class Quest2 {

protected int val;

protected String name;

protected float salary;

protected int   age;

protected float amount;

// assume constructors and other methods are defined

}

Explanation / Answer

Quest2.java

public class Quest2 {
protected int val;
protected String name;
protected float salary;
protected int age;
protected float amount;
// assume constructors and other methods are defined
public boolean equals( Object obj ) {
   Quest2 q = (Quest2)obj;
   if(this.name.equals(q.name) && this.age == q.age && this.val== q.val){
       return true;
   }
   else{
       return false;
   }
}

}