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

Create a class called FitnessMember that has only one variable, called name. The

ID: 3770248 • Letter: C

Question

Create a class called FitnessMember that has only one variable, called name. The person class should have a constructor with no parameters, a constructor with a parameter, a mutator function and an accessor function. Also, include a function to display the name.

Define a class called Athlete which is derived from FitnessMember. An Athlete record has the Athlete's name (defined in the FitnessMember class) and ID number of type String.

Define a class called Trainer whose objects are records for a fitness centers trainers. Derive this class from the class FitnessMember. A Trainer record has the Trainer's name (defined in the FitnessMember class) and a specialty as a String (for example, Weight, Aquatics, Cardio, Nutrition, etc.), and an training session fee (use the type double).

A Billing object will contain an Athlete object and a Trainer object. Give all your classes a reasonable complement of constructors, and accessor and mutator functions. Write a main test program that creates at least two Athletes, at least two Trainers, and at least two Billing records and displays the total income from the Billing records. Your tests should test all the functions and constructors defined in your program.

Explanation / Answer

Fitness Member:

public class FitnessMember {

   private String name;

   public FitnessMember() {
       this.name = null;
   }

   public FitnessMember(String name) {
       this.name = name;
   }

   public String getName() {
       return name;
   }

   public void setName(String name) {
       this.name = name;
   }

   public void printName() {
       System.out.println(this.name);
   }
}

Athelete:

public class Athlete extends FitnessMember {
   private String id;

   public Athlete(String id) {
       this.id = id;
   }

   public String getId() {
       return id;
   }

   public void setId(String id) {
       this.id = id;
   }
}

Trainer

public class Trainer extends FitnessMember {
   private String speciality;
   private double fee;

   public Trainer(String speciality, double fee) {
       this.speciality = speciality;
       this.fee = fee;
   }

   public String getSpeciality() {
       return speciality;
   }

   public void setSpeciality(String speciality) {
       this.speciality = speciality;
   }

   public double getFee() {
       return fee;
   }

   public void setFee(double fee) {
       this.fee = fee;
   }

}

Billing:

public class Billing {
   private Athlete athlete;
   private Trainer trainer;

   public Billing(Athlete athlete, Trainer trainer) {
       this.athlete = athlete;
       this.trainer = trainer;
   }

   public Athlete getAthlete() {
       return athlete;
   }

   public void setAthlete(Athlete athlete) {
       this.athlete = athlete;
   }

   public Trainer getTrainer() {
       return trainer;
   }

   public void setTrainer(Trainer trainer) {
       this.trainer = trainer;
   }
}

Runner:

public class Runner {

   public static void main(String[] args) {
       Athlete athlete1 = new Athlete("A");
       Athlete athlete2 = new Athlete("B");

       Trainer trainer1 = new Trainer("Weight", 50);
       Trainer trainer2 = new Trainer("Aquatics", 100);

       Billing billing1 = new Billing(athlete1, trainer1);
       Billing billing2 = new Billing(athlete2, trainer2);

       System.out.println(billing1.getTrainer().getFee()
               + billing2.getTrainer().getFee());

   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote