Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

imageimage

imageimageimageimage

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

Step: 1

To implement the equals method for the StepsFitnessTracker class as well as for the DistanceFitnessTracker and HeartRateFitnessTracker subclasses you ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Starting Out With Java From Control Structures Through Data Structures

Authors: Tony Gaddis

6th Edition

0133957055, 978-0133957051

More Books

Students also viewed these Programming questions

Question

What is the role of cognition and thought in learning?

Answered: 1 week ago

Question

What class do you use to create a menu bar?

Answered: 1 week ago