Question

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

please 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.

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
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution=> Please do comment in case of any query. Please make sure to read all the comments in the program. I have define all the required class and enum mention in the question.

Code:-

import java.util.*;

//Enum Datatype for Muscle
enum Muscle
{
   Abs, Back, Biceps, Chest, Arms, Glutes, Shoulders, Triceps, Legs, Cardio;
}

//Enum Datatype For Intensity
enum Intensity{
   HIGH, MEDIUM, LOW;
}

//Fitness Interface
interface Fitness
{
// abstract method
   //This method return the array of the muscle that is going to be affected by the Execise
public Muscle[] muscleTargeted();
//This method returns the total amount of calorie burnt by the exercise for the duration number of minutes for a person with the given weigh
public double calorieLoss(Intensity intensity, double weight, int duration);
// returns a short description of the fitness type
public String description();
  
}

//Abstract Class For Aerobic
abstract class Aerobic implements Fitness {
  
   public abstract Muscle[] muscleTargeted();
public abstract double calorieLoss(Intensity intensity, double weight, int duration);
  
public String description() {
   return "Aerobic means \"with oxygen.\".";
}

}

//Enum for SwimmingType
enum SwimmingType{
   ButterflyStroke, Breaststroke, Freestyle;
}

class Swimming extends Aerobic{
  
   private SwimmingType swimmingType;
  
   //Default Constructor for initilizes SwimmingType to Freestyle.
   public Swimming() {
       this.swimmingType=SwimmingType.Freestyle;
   }
  
   //Constructor for initilizes SwimmingType to given type.
   public Swimming(SwimmingType type) {
       this.swimmingType=type;
   }
   //Getter and Setter of swimmingType
   public SwimmingType getSwimmingType() {
       return swimmingType;
   }
  
   public void setSwimmingType(SwimmingType swimmingType) {
       this.swimmingType = swimmingType;
   }
  
   //Return the name of the class
   public String description() {
   return "Swimming";
}
  
   //No information given for this method for the swimming class
   @Override
   public Muscle[] muscleTargeted() {
       // TODO Auto-generated method stub
       return null;
   }

   //No information given for this method for the swimming class
   @Override
   public double calorieLoss(Intensity intensity, double weight, int duration) {
       // TODO Auto-generated method stub
       return 0;
   }
  
  
}

class Cycling extends Aerobic{

   //Return the name of the class
       public String description() {
       return "Cycling";
   }
      
   //
   @Override
   public Muscle[] muscleTargeted() {
       //These are the muscles affects by cycling
       Muscle[] arr = {Muscle.Glutes, Muscle.Cardio, Muscle.Legs};
       return arr;
   }

   ////No information given for the method for the swimming class
   @Override
   public double calorieLoss(Intensity intensity, double weight, int duration) {
       // TODO Auto-generated method stub
       return 0;
   }
  
}

Please do comment in case of any Query.

Hope you will like this answer.

Thanks.

Add a comment
Know the answer?
Add Answer to:
please write code in java and comment. thanks. the program is about interface . Implement the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • please write code in java, assignment is due soon Thanks. public interface Named The Named interface...

    please write code in java, assignment is due soon Thanks. public interface Named The Named interface is a simple interface which applies to anything which has a name. The only thing required is the following method: String name() which returns the name of the instance. public interface MessageSink, It includes: void deliver(Named sender, String message) delivers the specified message from the given sender. public interface Sharable, which is Named, It includes no method. public abstract class GeneralCapability It incudes: The...

  • please write program in java and comment the code clearly. I am providing previous classes Media...

    please write program in java and comment the code clearly. I am providing previous classes Media and payment codes to be used for this class.(its not a big code to write , it seems ,because i added previous classes , pleases help. public class Media { String name; int year;    // a constructor which initializes the media with the provided name and publication year. public Media(String name, int year) { this.name = name; this.year = year; }    //...

  • Need help with a few questions! Using the JAVA language please. 1) exercises - branching Write...

    Need help with a few questions! Using the JAVA language please. 1) exercises - branching Write a method whatToWear(int temp) that takes a temperature and then outputs a string for what to wear in different weather conditions. There must be at least 3 categories. For example, whatToWear(90) might return “shorts” and whatToWear(30) might return “down coat” 2) Enum exercise • Define an enum Seasons, and rewrite the whatToWear method to use enums and switch statement 8) 2D array exercise 1....

  • use intellij idea main java wp the professor. Please make sure to only implement what is...

    use intellij idea main java wp the professor. Please make sure to only implement what is asked for. You may not add any instance variables to any class, though you may create local variables inside of a method to accomplish its task. No other methods should be created other than the ones listed here. Step 1 Develop the following interface: Interface Name: Queue Interface<T> Access Modifier: public Methods Name: isEmpty Access modifier: public Parameters: none Return type: boolean Name: dequeue...

  • In java please: TotalCostForTicket interface Create interface that includes one variable taxRate which is .09. It...

    In java please: TotalCostForTicket interface Create interface that includes one variable taxRate which is .09. It also includes an abstract method calculateTotalPrice which has no parameters and returns a value of type double. public abstract class Ticket { //There is a public static instance variable of type double for the basePrice. public static double basePrice; // private int theaterNumber; private int seatNumber; private boolean isTicketSold; private boolean isTicketReserved; public Ticket(int theaterNumber, int seatNumber) { this.theaterNumber = theaterNumber; this.seatNumber = seatNumber;...

  • This question is about java program. Please show the output and the detail code and comment.And...

    This question is about java program. Please show the output and the detail code and comment.And the output (the test mthod )must be all the true! Thank you! And the question is contain 7 parts: Question 1 Create a Shape class with the following UML specification: (All the UML "-" means private and "+" means public) +------------------------------------+ | Shape | +------------------------------------+ | - x: double | | - y: double | +------------------------------------+ | + Shape(double x, double y) | |...

  • This is the question about object-oriend programming(java) please show the detail comment and prefect code of...

    This is the question about object-oriend programming(java) please show the detail comment and prefect code of each class, Thank you! This question contain 7 parts(questions) Question 1 Create a class a class Cat with the following UML diagram: (the "-" means private , "+" means public) +-----------------------------------+ | Cat | +-----------------------------------+ | - name: String | | - weight: double | +-----------------------------------+ | + Cat(String name, double weight) | | + getName(): String | | + getWeight(): double | |...

  • Java Homework Help. Can someone please fix my code and have my program compile correctly? Thanks...

    Java Homework Help. Can someone please fix my code and have my program compile correctly? Thanks for the help. Specifications: The class should have an int field named monthNumber that holds the number of the month. For example, January would be 1, February would be 2, and so forth. In addition, provide the following methods. A no- arg constructor that sets the monthNumber field to 1. A constructor that accepts the number of the month as an argument. It should...

  • 1 Overview For this assignment you are required to write a Java program that plays (n,...

    1 Overview For this assignment you are required to write a Java program that plays (n, k)-tic-tac-toe; (n, k)-tic- tac-toe is played on a board of size n x n and to win the game a player needs to put k symbols on adjacent positions of the same row, column, or diagonal. The program will play against a human opponent. You will be given code for displaying the gameboard on the screen. 2 The Algorithm for Playing (n, k)-Tic-Tac-Toe The...

  • Must be in Java. Show proper reasoning with step by step process. Comment on the code...

    Must be in Java. Show proper reasoning with step by step process. Comment on the code please and show proper indentation. Use simplicity. Must match the exact Output. CODE GIVEN: LineSegment.java LineSegmentTest.java Point.java public class Point { private double x, y; // x and y coordinates of point /** * Creates an instance of Point with the provided coordinates * @param inX the x coordinate * @param inY the y coordinate */ public Point (double inX, double inY) { this.x...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT