Question
In java add an equals method to the Project class so that two Project objects are equal if both of their switches are in the
In java add an equals method to the Project class so that two Project objects are equal if both of their switches are in the same states. Also, add a hashcode method to this class so that if two Project objects are considered equal, then they produce the same hashcode.
public class Project
{
public static boolean switchA;
public static boolean switchB;
public Project()
{
this.switchA = true;
this.switchB = false;
}
public void flip1()
{
switchA = !switchA;
}
public void flip2()
{
switchB = !switchB;
}
public boolean isLightOn()
{
return switchA == switchB;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started