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 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...
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 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...
Write a program in Java Design and implement simple matrix manipulation techniques program in java. Project...
Write a program in Java Design and implement simple matrix manipulation techniques program in java. Project Details: Your program should use 2D arrays to implement simple matrix operations. Your program should do the following: • Read the number of rows and columns of a matrix M1 from the user. Use an input validation loop to make sure the values are greater than 0. • Read the elements of M1 in row major order • Print M1 to the console; make...
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...
Write this code in java and don't forget to comment every step. Write a method which...
Write this code in java and don't forget to comment every step. Write a method which asks a baker how hot their water is, and prints out whether it is OK to make bread with the water. If the water is at or above 110F, your method should print "Too Warm." If the water is below 90.5F, print "Too Cold." If it is in between, print "Just right to bake!" For example, if the user inputs the number 100.5, the...
please write the java code so it can run on jGRASP Thanks! CODE 1 1 /**...
please write the java code so it can run on jGRASP Thanks! CODE 1 1 /** 2 * SameArray2.java 3 * @author Sherri Vaseashta4 * @version1 5 * @see 6 */ 7 import java.util.Scanner;8 public class SameArray29{ 10 public static void main(String[] args) 11 { 12 int[] array1 = {2, 4, 6, 8, 10}; 13 int[] array2 = new int[5]; //initializing array2 14 15 //copies the content of array1 and array2 16 for (int arrayCounter = 0; arrayCounter < 5;...
Suppose the interface and the class of stack already implemented, Write application program to ( java)...
Suppose the interface and the class of stack already implemented, Write application program to ( java) 1- insert 100 numbers to the stack                         2- Print the even numbers 3- Print the summation of the odd numbers
Using a (GUI interface), write a Java program that simulates an ATM machine with the following...
Using a (GUI interface), write a Java program that simulates an ATM machine with the following options menu: "Welcome" 1. Deposit to account 2. Withdraw 3. Exit
In Java Please!!! 6.22 LAB: Python and sqlite basics Write a Python program that connects to...
In Java Please!!! 6.22 LAB: Python and sqlite basics Write a Python program that connects to a sqlite database. Create a table called Horses with the following fields: id (integer): a primary key and not null name (text) breed (text) height (real) birthday (text) Next, insert the following data row into the Horses table: id: 1 name: 'Babe' breed: 'Quarter Horse' height: 15.3 birthday: '2015-02-10' Output all records from the Horses table. Ex: With the above row inserted, the output...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT