Question

In: Computer Science

write code in java and comment. thanks. the program is about interface . Implement the basics...

write code in java and comment. thanks. the program is about interface .

  1. Implement the basics of Fitness and types of Fitness: Aerobic.
  2. Implement specific Fitness types such as Swimming, Cycling,

Fitness Task:
public interface Fitness

(10pts) This will be used as a starting point for deriving any specific Fitness type. Every fitness exercise type has one or more muscle group it affects. Therefor a Fitness has the following abstarct method (Note that all methods in an interface are abstract by default):

  • public Muscle [ ] muscleTargeted() A method that returns the muscle that is going to be affected by the fitness. Note that the return type of the method is Muscle. A human body has a finite number of muscle parts that can be affected by fitness exercises. Define an enum datatype called Muscle with the follwoing member values Abs,Back,Biceps,Chest,Arms,Glutes,Shoulders,Triceps,Legs,Cardio
  • public double calorieLoss(Intensity intensity, double weight, int duration) - returns the total amount of calorie burnt by the exercise for the duration number of minutes for a person with the given weight. Intensity can be HIGH, MEDIUM, LOW. Note that Intensity is a good candidate to be definied as enum.
  • public String description() a method that returns a short decription of the fitness type.

Aerobic Task:

(10pts) Aerobic means "with oxygen." The purpose of aerobic conditioning is to increase the amount of oxygen that is delivered to your muscles, which allows them to work longer. Aerobic is a Fitness. However, we cannot give the actual implementation for the methods muscleTargeted() and calorieLoss() as we don't know the actual aerobic exercise. The descripton() method returns the string Aerobic means "with oxygen.". Note that Aerobic is a good candidate to be abstract class.

public class Swimming, which is an Aerobic

This class represents an actual Aerobic exercise, i.e., it extends Aerobic class, that a user can do to burn calories. The calculation of how much calorie will be burn relies on a key value known as a MET, which stands for metabolic equivalent.One "MET" is "roughly equivalent to the energy cost of sitting quietly," and can be considered 1 kcal/kg/hour. The MET values of some of the exercises that we consider of this project are displayed in the following table. The MET value multiplied by weight in kilograms tells you calories burned per hour (MET*weight in kg=calories/hour). There are different types swimming: Butterflystroke, Freestyle, and Breaststroke. These different types of swimming activities affects different muscles. Butterflystroke: Abs,Back, Shoulders,Biceps,Triceps; Breastsstroke: Glutes, Cardio; Freestyle: Arms,Legs,Cardio.

Define a class Swimming. The class must include the following:

  • public Swimming (SwimmingType type) - defines the constructor for the class. You need to define an enum datatype called SwimmingTypewith members ButterflyStroke,Breaststroke,Freestyle
  • public Swimming () - a default constructor for the class that initilizes SwimmingType to Freestyle.
  • public void setSwimmingType(SwimmingType type) A setter for the swimmingType.
  • public SwimmingType getSwimmingType() A getter for the swimmingType.
  • @Override public String description() returns the name of the class.

public class Cycling, which is an Aerobic

(10pts) This class represents an actual Aerobic exercise, i.e., it extends Aerobic class, that a user can do to burn calories. Cycling affects muscles: Glutes, Cardio, Legs. Define a class Cycling. The class also has:

  • @Override public String description() returns the name of the class.
Exercise HIGH MEDIUM LOW
Swimming 10.0 8.3 6.0
Cycling 14.0 8.5 4.0
Yoga 4.0 3.0 2.0
Weightlifting 6.0 5.0 3.5
Plyometrics 7.4 4.8 2.5
Tai Chi 5.0 3.0 1.5
Squat 7.0 5.0 2.5
Pull-Up 7.5 6.0 4.8

Solutions

Expert Solution

Fitness.java

======================

package fitness;

public interface Fitness {

   // A method that returns the muscle that is going to be affected by the fitness.
   public Muscle[] muscleTargeted();
  
   // returns the total amount of calorie burnt by the exercise
   // for the duration number of minutes for a person with the given weight.
   public double calorieLoss(Intensity intensity, double weight, int duration);

   // returns a short description of the fitness type.
   public String description();
  
}

==========================

Muscle.java

==========================

package fitness;

public enum Muscle {
   Abs, Back, Biceps, Chest, Arms, Glutes, Shoulders, Triceps, Legs, Cardio
}

===========================

Intensity.java

===========================

package fitness;

public enum Intensity {
   HIGH, MEDIUM, LOW
}

==========================

Aerobic.java

==========================

package fitness;

public abstract class Aerobic implements Fitness{

   // abstract methods must be implemented in child classes
   public abstract Muscle[] muscleTargeted();
   public abstract double calorieLoss(Intensity intensity, double weight, int duration);

   @Override
   public String description() {
       return this.getClass().getSimpleName() + " with oxygen.";
   }

}

============================

Swimming.java

============================

package fitness;

public class Swimming extends Aerobic{
  
   // data field
   private SwimmingType type;
  
   // enum data type to represent SwimmingType
   public static enum SwimmingType { ButterflyStroke, Breaststroke, Freestyle };

   // constructor with parameter
    public Swimming (SwimmingType type) {
       this.type = type;
    }
  
    // default constructor
    public Swimming () {
       // initialize SwimmingType to Freestyle
       this(SwimmingType.Freestyle);
    }
  
    // setter
    public void setSwimmingType(SwimmingType type) {
       this.type = type;
    }
  
    // getter
    public SwimmingType getSwimmingType() {
       return type;
    }

   @Override
   public Muscle[] muscleTargeted() {
       // create a Muscle array to return
       Muscle[] muscles = null;
       // get targeted muscles according to type of swimming
       if(type == SwimmingType.ButterflyStroke) {
           muscles = new Muscle[]{Muscle.Abs, Muscle.Back, Muscle.Shoulders, Muscle.Biceps, Muscle.Triceps};
       }
       else if(type == SwimmingType.Breaststroke) {
           muscles = new Muscle[]{Muscle.Glutes, Muscle.Cardio};
       }
       else if(type == SwimmingType.Freestyle) {
           muscles = new Muscle[]{Muscle.Arms, Muscle.Legs, Muscle.Cardio};
       }
       return muscles;
   }

   @Override
   public double calorieLoss(Intensity intensity, double weight, int duration) {
       // MET stands for metabolic equivalent
       // 1 MET = 1 kcal/kg/hour
       // calories burned per hour (MET*weight in kg=calories/hour)
       // from table intensity value    HIGH    MEDIUM    LOW
       //                               10.0    8.3    6.0
      
       // calculate calorieLoss
       double calorie = 0.0;
       if(intensity == Intensity.HIGH) {
           calorie = 10.0*weight*duration;
       }
       else if(intensity == Intensity.MEDIUM) {
           calorie = 8.3*weight*duration;
       }
       else if(intensity == Intensity.LOW){
           calorie = 6.0*weight*duration;
       }
       return calorie;
   }
  
   /*
    @Override
    public String description() {
       // call parent class description to add in string of description
       return this.getClass().getSimpleName() + super.description();
    }
   */
}

==========================

Cycling.java

==========================

package fitness;

public class Cycling extends Aerobic{

   @Override
   public Muscle[] muscleTargeted() {
       // return targeted muscles
       return new Muscle[] {Muscle.Glutes, Muscle.Cardio, Muscle.Legs};
   }

   @Override
   public double calorieLoss(Intensity intensity, double weight, int duration) {
       // MET stands for metabolic equivalent
       // 1 MET = 1 kcal/kg/hour
       // calories burned per hour (MET*weight in kg=calories/hour)
       // from table intensity value    HIGH    MEDIUM    LOW
       //                               14.0    8.5    4.0
              
       // calculate calorieLoss
       double calorie = 0.0;
       if(intensity == Intensity.HIGH) {
           calorie = 14.0*weight*duration;
       }
       else if(intensity == Intensity.MEDIUM) {
           calorie = 8.5*weight*duration;
       }
       else if(intensity == Intensity.LOW){
           calorie = 4.0*weight*duration;
       }
       return calorie;
   }

   /*
   @Override
   public String description() {
   // call parent class description to add in string of description
          return this.getClass().getSimpleName() + super.description();
   }
   */
}

========================

Main.java

========================

package fitness;

import fitness.Swimming.SwimmingType;

public class Main {
  
   // main method to run the program
   public static void main(String[] args) {
       // create exercise to calculate calories burnt
      
       System.out.println("Person with 62kg weight swimming with high intensity for 2 hours");
       Swimming s1 = new Swimming();
       System.out.println(s1.description());
       System.out.println("Total calories burnt: " + s1.calorieLoss(Intensity.HIGH, 62, 2) + " Kcal");
       System.out.print("Muscle targeted: ");
       for(int i=0; i<s1.muscleTargeted().length; i++) {
           System.out.print(s1.muscleTargeted()[i].name() + " ");
       }
       System.out.println();
       System.out.println("switching swimming style");
       s1.setSwimmingType(SwimmingType.Breaststroke);
       System.out.print("Muscle targeted: ");
       for(int i=0; i<s1.muscleTargeted().length; i++) {
           System.out.print(s1.muscleTargeted()[i].name() + " ");
       }
       System.out.println();
       System.out.println();
      
       System.out.println("Cycling with 56 kg for 3 hours with midium intensity");
       Cycling c1 = new Cycling();
       System.out.println(c1.description());
       System.out.println("Total calories burnt: " + c1.calorieLoss(Intensity.MEDIUM, 56, 3) + " Kcal");
       System.out.print("Muscle targeted: ");
       for(int i=0; i<c1.muscleTargeted().length; i++) {
           System.out.print(c1.muscleTargeted()[i].name() + " ");
       }
      
      
       System.out.println();
      
   }

}

let me know if you have any doubt or problem. thank you.


Related Solutions

Please write code in java and comment. Thanks. I would appreciate that. Fitness Task: public interface...
Please write code in java and comment. Thanks. I would appreciate that. Fitness Task: public interface Fitness public Muscle [ ] muscleTargeted() A method that returns the muscle that is going to be affected by the fitness. Note that the return type of the method is Muscle. A human body has a finite number of muscle parts that can be affected by fitness exercises. Define an enum datatype called Muscle with the follwoing member values Abs,Back,Biceps,Chest,Arms,Glutes,Shoulders,Triceps,Legs,Cardio public String description() a...
Please write code in java and comment . thanks Item class A constructor, with a String...
Please write code in java and comment . thanks Item class A constructor, with a String parameter representing the name of the item. A name() method and a toString() method, both of which are identical and which return the name of the item. BadAmountException Class It must be a RuntimeException. A RuntimeException is a subclass of Exception which has the special property that we wouldn't need to declare it if we need to use it. It must have a default...
Please use Java language! with as much as comment! thanks! Write a program that displays a...
Please use Java language! with as much as comment! thanks! Write a program that displays a frame with a three labels and three textfields. The labels should be "width:", "height:", and "title:" and should each be followed by one textfield. The texfields should be initialized with default values (Example 400, 600, default title), but should be edited by the user. There should be a button (label it whatever you want, I don't care). If you click the button, a new...
Please use Java language! with as much as comment! thanks! Write a program that displays a...
Please use Java language! with as much as comment! thanks! Write a program that displays a frame with a three labels and three textfields. The labels should be "width:", "height:", and "title:" and should each be followed by one textfield. The texfields should be initialized with default values (Example 400, 600, default title), but should be edited by the user. There should be a button (label it whatever you want, I don't care). If you click the button, a new...
This question is about java program. Please show the output and the detail code and comment...
This question is about java program. Please show the output and the detail code and comment of the each question and each Class and interface. And the output (the test mthod )must be all the true! Thank you! Question1 Create a class Animal with the following UML specification: +-----------------------+ | Animal | +-----------------------+ | - name: String | +-----------------------+ | + Animal(String name) | | + getName(): String | | + getLegs(): int | | + canFly(): boolean | |...
This problem is about java program and please show the detail comment and code in each...
This problem is about java program and please show the detail comment and code in each class. Thank you! Create four classes with the following UML diagrams: (The "-" means private and the testBankAccount() testMobilePhone() testChocolate() testStudent() all static +-----------------------------+ | BankAccount | +-----------------------------+ | - money: int | +-----------------------------+ | + BankAccount(int money) | | + getMoney(): int | | + setMoney(int money): void | | + testBankAccount(): void | +-----------------------------+ +------------------------------------------------+ | MobilePhone     | +------------------------------------------------+ | -...
This is for a java program. Payroll System Using Inheritance and Polymorphism 1. Implement an interface...
This is for a java program. Payroll System Using Inheritance and Polymorphism 1. Implement an interface called EmployeeInfo with the following constant variables: FACULTY_MONTHLY_SALARY = 6000.00 STAFF_MONTHLY_HOURS_WORKED = 160 2. Implement an abstract class Employee with the following requirements: Attributes last name (String) first name (String) ID number (String) Sex - M or F Birth date - Use the Calendar Java class to create a date object Default argument constructor and argument constructors. Public methods toString - returning a string...
This the question about the java and please show the detail comment and code of each...
This the question about the java and please show the detail comment and code of each class.Thank you. And the "+" means "public" the "-" means "private" and testBankAccount(): void testMobilePhone(): void testChocolate(): void all are static Create four classes with the following UML diagrams: +-----------------------------+ | BankAccount | +-----------------------------+ | - money: int | +-----------------------------+ | + BankAccount(int money) | | + getMoney(): int | | + setMoney(int money): void | | + testBankAccount(): void | +-----------------------------+ +------------------------------------------------+ |...
This is the question about the java problem, please give the detail comment and code of...
This is the question about the java problem, please give the detail comment and code of each class. Please write tests for all the code of all the classes Thank you Create a class Mammal with the following UML diagrams: +---------------------------------+ | Mammal | +---------------------------------+ | - name: String | +---------------------------------+ | + Mammal(String name) | | + getName(): String | | + isCookable(): boolean | | + testMammal(): void | (this method is static ) +---------------------------------+ The isCookable method...
Please write code in java and comment . thanksItem classA constructor, with a String...
Please write code in java and comment . thanksItem classA constructor, with a String parameter representing the name of the item.A name() method and a toString() method, both of which are identical and which return the name of the item.BadAmountException ClassIt must be a RuntimeException. A RuntimeException is a subclass of Exception which has the special property that we wouldn't need to declare it if we need to use it.It must have a default constructor.It must have a constructor which...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT