Question: Write an equals method for the StepsFitnessTracker class thattests whether the one object is equal to another object that ispassed as an argument (Object otherObject).

Write an equals method for the StepsFitnessTracker class thattests whether the one object is equal to another object that ispassed as an argument (Object otherObject). The Object superclassprovides an equals method that tests if two object references areequal. Your new equals method should override the Object equalsmethod, and should test the following: ? Return true if the current(this) object, and otherObject are identical references (hint: youcan use the == operator for this). ? Returns false if otherObjectis null. ? Returns false if the current (this) object andotherObject have different classes (hint: you can use thegetClass() method provided by the Object superclass, see the Java 8API documentation for details). ? Casts otherObject to aStepsFitnessTracker, and tests for equality of each instancevariable1 , if the instance variables are the same the methodshould return true

Now write an equals method for the DistanceFitnessTracker andHeartRateFitnessTracker classes that: ? Use the superclass equalsmethod, and return false if this method fails. ? Casts theparameter to either HeartRateFitnessTracker orDistanceFitnessTracker. ? Tests for equality of the subclassinstance fields. Please, use JUnit testing and write a test classnamed TestFTEquals to test that these new equals methods workproperly. For inspiration, you can have a look at the test classesprovided (TestFitnessTracker, TestDistanceFitnessTracker,TestStepsFitnessTracker, and TestHeartRateFitnessTracker) as theyare already providing you some basic tests about how to test forequality of objects.

I wrote the equal methods for the classes they need but I amhaving trouble solve the TESTFTEQUAL Junit test

public class HeartRate Fitness Tracker extends Fitness Tracker { // Cumulative movingaverage HeartRate HeartRate avgHeartRate; // Number of heart rate measurements int numMeasurements;

public HeartRateFitness Tracker(String modelName, HeartRate heartRate) { to single measurement } }super(modelName); // Only one HeartRate to begin with; average is equal publicvoid addHeartRate(HeartRate heartRateToAdd) { // Calculate cumulative moving average of heart rate// See https://en.wikipedia.org/wiki/Moving_average double newHR = heartRateToAdd.getValue(); double cmaHR= this.avgHeartRate.getValue(); double cmaNext

I added all the code needed please provide it has soonas possible please please

public class HeartRate Fitness Tracker extends Fitness Tracker { // Cumulative moving average HeartRate HeartRate avgHeartRate; // Number of heart rate measurements int numMeasurements; public HeartRateFitness Tracker(String modelName, HeartRate heartRate) { to single measurement } } super(modelName); // Only one HeartRate to begin with; average is equal public void addHeartRate(HeartRate heartRateToAdd) { // Calculate cumulative moving average of heart rate // See https://en.wikipedia.org/wiki/Moving_average double newHR = heartRateToAdd.getValue(); double cmaHR= this.avgHeartRate.getValue(); double cmaNext = (newHR + (cmaHR* numMeasurements))/(numMeasurements + 1); } this.avgHeartRate = heartRate; this.numMeasurements = 1; this.avgHeartRate.setValue(cmaNext); // Getter for average heart rate public HeartRate getAvgHeartRate() { return avgHeartRate; numMeasurements ++; public String toString() { return "Heart Rate Tracker " + getModelName() + "; Average Heart Rate: " + getAvgHeartRate().getValue() + measurements"; } } ", for " + numMeasurements +" @Override public boolean equals(Object obj) { // TODO Implement a method to check equality if(this == obj) // it will check if both the references are refers to same object return true; if(obj == null || obj.getClass()!=this.getClass()) //it check the argument of the type HeartRate Fitness Tracker by comparing the classes of the passed argument and this object. return false; HeartRateFitness Tracker HRFT= (HeartRateFitness Tracker)obj; // type casting of the argument. return (HRFT.avgHeartRate == this.avgHeartRate);// comparing the state of argument with the state of 'this' Object.

Step by Step Solution

3.44 Rating (154 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To implement the equals method for the StepsFitnessTracker class as well as for the DistanceFitnessTracker and HeartRateFitnessTracker subclasses you ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!