Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public class Runner extends Athlete{ public Runner (String firstName, String las

ID: 3814245 • Letter: P

Question

public class Runner extends Athlete{ public Runner (String firstName, String lastName)( Super (firstName, lastNAme, "Running"); my Number ofRaces myMilesRaced 0; public void race (double raceLength){ System, out pri (getName is racing in a race Length mile race. my Number OfRaces++; my Miles Raced raceLength; public int getRaces0l return myNumberOfRaces; public double getMilesRaced() return my MilesRaced; private int my NumberOf Races; private double myMilesRaced; A Marathoner is a long distance Runner. Write the Marathoner class according to the following specifications. The Marathoner is a subclass of the Runner class. The Marathoner's sport is "Running". However, in order for a race to "count" as a race for the Marathoner, the race must be at least 10 miles in length. If it is shorter than 10 miles, the race counts as a training run and the training time credited to myHoursTraining is 8 Vi minutes for each mile run. The variable myNumberof Races is not incremented, nor is myMilesRaced increased if there race is shorter than 10 miles in length. The Marathoner class will override the Runner's race method so that these specifications are met. class marathon er extends R nn er Prblic mara mor ur string. First Name string Las Abme) super First Nome, uest Nome aces My Miles ed void Race (double race length blit if race length t run race ength T. 160 return Private int my Number -t fores else inte int. my M len race left faces

Explanation / Answer

Issue in given program with field myHoursOfTraining. It should be private double myHoursTraining

Marathoner.java
public class Marathoner extends Runner {

   public Marathoner(String firstName, String lastName) {
       super(firstName, lastName);
       myHoursTraining = 0;
   }
  
   public void race(double raceLength)
   {
       if (raceLength < 10)
       {
           System.out.println(getName() + " is training by running in a " + raceLength+ " miles race.");
           myHoursTraining += 8.5*raceLength;
       }
       else
       {
           super.race(raceLength);
       }
   }
  
   public double getHoursTrained()
   {
       return myHoursTraining;
   }
  
   private double myHoursTraining;

}

Please rate positively if it answer your question. Comment if something is unclear.