Java Note that the class FitnessTracker is at the top of the inheritance hierarchy and that each of the classes inheriting it   To simplify the problem, our classes are only storing one type of measurement, either the total number of steps class StepsFitnessTracker, or the total distance walked class DistanceFitnessTracker, or the average heart rate class HeartRateFitnessTracker. As opposed to what happens with commercial fitness trackers, none of our trackers is able to track simultaneously distance, heart rate and steps. Each of these classes also have a method with a signature similar to: public void addXYZ(XYZ newMeasurement) For example: - StepsFitnessTracker has addSteps(Steps steps) - HeartRateFitnessTracker has addHeartRage(HeartRate newHeartRate) These methods are meant to add more measurements to these objects, and they are meant to either keep the total distance, number of steps walked, or average heart rate. See the code provided and the comments in the code to understand how they work. Task  Create an object of type FitnessExperiment that stores an array of StepsFitnessTracker, DistanceFitnessTracker, and HeartRateFitnessTracker objects. You could use code such as the following to initialise the array containing the fitness tracker measurements: FitnessTracker[] trackers = { new StepsFitnessTracker("steps", new Steps(230)), new StepsFitnessTracker("steps2", new Steps(150)), new StepsFitnessTracker("steps2", new Steps(150)), new HeartRateFitnessTracker("hr", new HeartRate(80)), new HeartRateFitnessTracker("hr", new HeartRate(80)) }; In the FitnessExperiment class, complete the implementation of the methods named getTotalSteps()and printExperimentDetails(). The comments in the code specify how they should operate and provide you with additional hints to get you started. You can use the method getSteps()in StepsFitnessTracker, but think how you will know the real type of each object in the array of fitness trackers (trackers in the example above). FitnessTracker HeartRateFitnessTracker DistanceFitnessTracker StepsFitnessTracker   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    }    */       } public class HeartRateFitnessTracker extends FitnessTracker {    // Cumulative moving average HeartRate    HeartRate avgHeartRate;    // Number of heart rate measurements    int numMeasurements;       public HeartRateFitnessTracker(String modelName, HeartRate heartRate) {        super(modelName);        // Only one HeartRate to begin with; average is equal to single measurement        this.avgHeartRate = heartRate;        this.numMeasurements = 1;    }       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.setValue(cmaNext);               numMeasurements ++;    }       // Getter for average heart rate    public HeartRate getAvgHeartRate() {        return avgHeartRate;    }    public String toString() {        return "Heart Rate Tracker " + getModelName() +                "; Average Heart Rate: " + getAvgHeartRate().getValue() +                ", for " + numMeasurements + " measurements";    }    /*    @Override    public boolean equals(Object obj) {        // TODO Implement a method to check equality    }    */       } public class StepsFitnessTracker extends FitnessTracker {    // Stores total number of steps    private Steps totalSteps;       public StepsFitnessTracker(String modelName, Steps steps) {        super(modelName);        this.totalSteps = steps;    }       // Add steps to the total    public void addSteps(Steps stepsToAdd) {        int numSteps = this.totalSteps.getValue() + stepsToAdd.getValue();        this.totalSteps.setValue(numSteps);    }       // Getter for total number of steps    public Steps getTotalSteps() {        return totalSteps;    }       public String toString() {        return "Steps Tracker " + getModelName() +                "; Total Steps: " + getTotalSteps().getValue();    }       /*    @Override    public boolean equals(Object obj) {        // TODO Implement a method to check equality    }    */       } Simply what we need to do is fix the three classes stepfitness,fitnesstracker and heartrate fitness and then create distance fitness and all this to fix the fitnessexpermient which stores one measurment from each   We are not allowed to change the code we are allowed to remove any part saying     "// TODO Implement a method to check equality" and replace it with a code to sastsfiy the code and its needs

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Java

Note that the class FitnessTracker is at the top of the inheritance hierarchy and that each of the classes inheriting it

 

To simplify the problem, our classes are only storing one type of measurement, either the total number of steps class StepsFitnessTracker, or the total distance walked class DistanceFitnessTracker, or the average heart rate class HeartRateFitnessTracker. As opposed to what happens with commercial fitness trackers, none of our trackers is able to track simultaneously distance, heart rate and steps. Each of these classes also have a method with a signature similar to: public void addXYZ(XYZ newMeasurement) For example: - StepsFitnessTracker has addSteps(Steps steps) - HeartRateFitnessTracker has addHeartRage(HeartRate newHeartRate) These methods are meant to add more measurements to these objects, and they are meant to either keep the total distance, number of steps walked, or average heart rate. See the code provided and the comments in the code to understand how they work.

Task  Create an object of type FitnessExperiment that stores an array of StepsFitnessTracker, DistanceFitnessTracker, and HeartRateFitnessTracker objects. You could use code such as the following to initialise the array containing the fitness tracker measurements: FitnessTracker[] trackers = { new StepsFitnessTracker("steps", new Steps(230)), new StepsFitnessTracker("steps2", new Steps(150)), new StepsFitnessTracker("steps2", new Steps(150)), new HeartRateFitnessTracker("hr", new HeartRate(80)), new HeartRateFitnessTracker("hr", new HeartRate(80)) }; In the FitnessExperiment class, complete the implementation of the methods named getTotalSteps()and printExperimentDetails(). The comments in the code specify how they should operate and provide you with additional hints to get you started. You can use the method getSteps()in StepsFitnessTracker, but think how you will know the real type of each object in the array of fitness trackers (trackers in the example above). FitnessTracker HeartRateFitnessTracker DistanceFitnessTracker StepsFitnessTracker

 

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
   }
   */
  
  
}

public class HeartRateFitnessTracker extends FitnessTracker {


   // Cumulative moving average HeartRate
   HeartRate avgHeartRate;
   // Number of heart rate measurements
   int numMeasurements;
  
   public HeartRateFitnessTracker(String modelName, HeartRate heartRate) {
       super(modelName);
       // Only one HeartRate to begin with; average is equal to single measurement
       this.avgHeartRate = heartRate;
       this.numMeasurements = 1;
   }
  
   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.setValue(cmaNext);
      
       numMeasurements ++;
   }
  
   // Getter for average heart rate
   public HeartRate getAvgHeartRate() {
       return avgHeartRate;
   }

   public String toString() {
       return "Heart Rate Tracker " + getModelName() +
               "; Average Heart Rate: " + getAvgHeartRate().getValue() +
               ", for " + numMeasurements + " measurements";
   }

   /*
   @Override
   public boolean equals(Object obj) {
       // TODO Implement a method to check equality
   }
   */
  
  

}

public class StepsFitnessTracker extends FitnessTracker {

   // Stores total number of steps
   private Steps totalSteps;
  
   public StepsFitnessTracker(String modelName, Steps steps) {
       super(modelName);
       this.totalSteps = steps;
   }
  
   // Add steps to the total
   public void addSteps(Steps stepsToAdd) {
       int numSteps = this.totalSteps.getValue() + stepsToAdd.getValue();
       this.totalSteps.setValue(numSteps);
   }
  
   // Getter for total number of steps
   public Steps getTotalSteps() {
       return totalSteps;
   }
  
   public String toString() {
       return "Steps Tracker " + getModelName() +
               "; Total Steps: " + getTotalSteps().getValue();
   }
  
   /*
   @Override
   public boolean equals(Object obj) {
       // TODO Implement a method to check equality
   }
   */
  
  

}

Simply what we need to do is fix the three classes stepfitness,fitnesstracker and heartrate fitness and then create distance fitness and all this to fix the fitnessexpermient which stores one measurment from each  

We are not allowed to change the code we are allowed to remove any part saying     "// TODO Implement a method to check equality" and replace it with a code to sastsfiy the code and its needs 

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
Transcribed Image Text: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
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY