Write a new class called DistanceFitnessTracker that extends FitnessTracker . DistanceFitnessTracker will represent a fitness tracker able to record only distance. In this Problem Sheet, you will not be asked to convert between distance units (i.e. the default behaviour of the Distance class will be used, namely, kilometres) In simple words distancefitnesstracker I provided is incomplete it needs to pass the test I provided I need my distancefitnesstracker: public class DistanceFitnessTracker extends FitnessTracker{ private Distance distance; public DistanceFitnessTracker(String modelName, Distance distance) { super(modelName); this.distance = distance ; } public Distance getDistance() { return distance; } } To pass this Junit test code: public class TestDistanceFitnessTracker { @Test public void testTrackersDifferentSumNotEqual() { DistanceFitnessTracker a = new DistanceFitnessTracker("hr", new Distance(20)); DistanceFitnessTracker b = new DistanceFitnessTracker("hr", new Distance(20)); b.addDistance(new Distance(10)); assertNotEquals(a, b); assertNotEquals(b, a); } } To make it simple the I need to implement distancefitnesstracker to store a distance and to pass the JUNit test I provided Distance.java public class Distance { // Enum of distance units public enum DistanceUnit { KILOMETRES, MILES } // Constants private static final double KMS_PER_MILE = 1.609; private static final double MILES_PER_KM = 0.621; // Instance variables private double value; private DistanceUnit distanceUnit; // Constructors public Distance(double value) { this.value = value; // Default unit is km this.distanceUnit = DistanceUnit.KILOMETRES; } public Distance(double value, DistanceUnit distanceUnit) { this.value = value; this.distanceUnit = distanceUnit; } // Methods: You should remove the comments and complete the method bodies for all the methods below // Think that all these methods are in the class for a reason, so you should use them all // DO NOT MODIFY the signature of these methods! public double getValue() { return value; } public double getValue(DistanceUnit unit) { if(unit==this.distanceUnit) return value; else{ if(unit==DistanceUnit.MILES) return convertToMiles(value); else if(unit==DistanceUnit.KILOMETRES) return convertToKilometers(value); } return 0; } public void setValue(double value) { this.value = value; } public DistanceUnit getDistanceUnit() { return distanceUnit; } public void changeDistanceUnit(DistanceUnit distanceUnit) { this.distanceUnit = distanceUnit; } public static double convertToMiles(double kilometers){ return kilometers*MILES_PER_KM; } public static double convertToKilometers(double miles){ return miles*KMS_PER_MILE; } public String toString() { return "Distance [value=" + value + ", distanceUnit=" + distanceUnit + "]"; } } FitnessTracker.java public class FitnessTracker { // String containing model name of fitness activity tracker private String modelName; public FitnessTracker(String modelName) { this.modelName = modelName; } public String getModelName() { return modelName; } @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 FitnessTracker by comparing the classes of the passed argument and this object. return false; FitnessTracker FT=(FitnessTracker)obj; // type casting of the argument. return (FT.modelName == this.modelName);// comparing the state of argument with the state of 'this' Object. Please solve do not say its complex. Its simple change the distancefitnesstracker code I provided to make it pass the testdistancefitnesstracker. Easy Please \ DistanceFitnessTracker extends FitnessTracker.java and imports from distance.java In one of the pictures I show you what failed when I run distancefitnesstracker through the Junit test. And in the second picutre I provide fitnesstracker
Write a new class called DistanceFitnessTracker that extends FitnessTracker . DistanceFitnessTracker will represent a fitness tracker able to
record only distance. In this Problem Sheet, you will not be asked to convert between distance units
(i.e. the default behaviour of the Distance class will be used, namely, kilometres)
In simple words distancefitnesstracker I provided is incomplete it needs to pass the test I provided
I need my distancefitnesstracker:
public class DistanceFitnessTracker extends FitnessTracker{
private Distance distance;
public DistanceFitnessTracker(String modelName, Distance distance) {
super(modelName);
this.distance = distance ;
}
public Distance getDistance() {
return distance;
}
}
To pass this Junit test code:
public class TestDistanceFitnessTracker {
@Test
public void testTrackersDifferentSumNotEqual() {
DistanceFitnessTracker a = new DistanceFitnessTracker("hr", new Distance(20));
DistanceFitnessTracker b = new DistanceFitnessTracker("hr", new Distance(20));
b.addDistance(new Distance(10));
assertNotEquals(a, b);
assertNotEquals(b, a);
}
}
To make it simple the I need to implement distancefitnesstracker to store a distance and to pass the JUNit test I provided
Distance.java
public class Distance {
// Enum of distance units
public enum DistanceUnit {
KILOMETRES,
MILES
}
// Constants
private static final double KMS_PER_MILE = 1.609;
private static final double MILES_PER_KM = 0.621;
// Instance variables
private double value;
private DistanceUnit distanceUnit;
// Constructors
public Distance(double value) {
this.value = value;
// Default unit is km
this.distanceUnit = DistanceUnit.KILOMETRES;
}
public Distance(double value, DistanceUnit distanceUnit) {
this.value = value;
this.distanceUnit = distanceUnit;
}
// Methods: You should remove the comments and complete the method bodies for all the methods below
// Think that all these methods are in the class for a reason, so you should use them all
// DO NOT MODIFY the signature of these methods!
public double getValue() {
return value;
}
public double getValue(DistanceUnit unit) {
if(unit==this.distanceUnit)
return value;
else{
if(unit==DistanceUnit.MILES)
return convertToMiles(value);
else if(unit==DistanceUnit.KILOMETRES)
return convertToKilometers(value);
} return 0;
}
public void setValue(double value) {
this.value = value;
}
public DistanceUnit getDistanceUnit() {
return distanceUnit;
}
public void changeDistanceUnit(DistanceUnit distanceUnit) {
this.distanceUnit = distanceUnit;
}
public static double convertToMiles(double kilometers){
return kilometers*MILES_PER_KM;
}
public static double convertToKilometers(double miles){
return miles*KMS_PER_MILE;
}
public String toString() {
return "Distance [value=" + value + ", distanceUnit=" + distanceUnit + "]";
}
}
FitnessTracker.java
public class FitnessTracker {
// String containing model name of fitness activity tracker
private String modelName;
public FitnessTracker(String modelName) {
this.modelName = modelName;
}
public String getModelName() {
return modelName;
}
@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 FitnessTracker by comparing the classes of the passed argument and this object.
return false;
FitnessTracker FT=(FitnessTracker)obj; // type casting of the argument.
return (FT.modelName == this.modelName);// comparing the state of argument with the state of 'this' Object.
Please solve do not say its complex. Its simple change the distancefitnesstracker code I provided to make it pass the testdistancefitnesstracker. Easy Please \
DistanceFitnessTracker extends FitnessTracker.java and imports from distance.java
In one of the pictures I show you what failed when I run distancefitnesstracker through the Junit test. And in the second picutre I provide fitnesstracker
![public class FitnessExperiment (
FitnessTracker(] fitnessTrackers;
public static void masin(String] args) {
// Constructor
public FitnessExperiment(FitnessTracker[) fitnessTrackers) {
this.fitnessTrackers = fitnessTrackers;
// Methods to implement:
// Implementation hint: Should it use the corresponding toString) methods for
// each of the objects stored in the fitnessTrackers array?
public String tostring) {
// TODO Implement
// Method displays in console the details of this experiment which include:
/I- Summary of the measurements of each individual fitness tracker
// (indicating if they are steps, distance or heart rate measurements)
/I - The total number of fitness trackers that participated in this experiment
/1-A summary of total number of steps and total distance walked in this experiment
/ Implementation hint: Should it use the toString() method right above this method?
public void printExperimentDetails() {
// TODO Implement
// Method should iterate through all fitness tracker step measurements and returns a double
// with the total step count (see Task 2)
/ Implementation hint: The instanceof operator and casting may become handy here
public int getTotalSteps() {
// TODO Implement
// Method should iterate through all fitness tracker distance measurements and returns a double with the total distance
// Implementation hint: The instanceof operator and casting may become handy here
public double getTotalDistance() (
// TODO Implement
public FitnessTrackerll getTrackersEqualTo(FitnessTracker tracker) {
// TODO Implement a method that finds the trackers which are equal to tracker
/ Implementation hint: use the above getTrackersEqualTo() method
public void printAlEqualTrackers(){
// TODO Implement a method which prints every duplicate tracker](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F5f47628f-fe73-4621-be65-b7982c832056%2Fd636ede7-b627-4af8-9c61-788df80eb47c%2Fft0106_processed.png&w=3840&q=75)
![Runs: 1/1
E Errors: 1
E Failures: 0
ukac.sheffield.com1003.problemsheet2.test.TestDistanceFitnessT
A testTrackersDifferentSumNotEqual (0.007 s)](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F5f47628f-fe73-4621-be65-b7982c832056%2Fd636ede7-b627-4af8-9c61-788df80eb47c%2F6zpfglg_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)