In: Computer Science
write code in java and comment. thanks. the program is about interface .
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):
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 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:
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 |
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.