Question

In: Computer Science

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 method that returns a short decription of the fitness type.

Anaerobic Task:

(10pts) Anaerobic is a Fitness and we cannot give the actual implementation for the methods muscleTargeted() as we don't know the actual Anaerobic exercise. The descripton() method returns the string Anaerobic means "without oxygen.". Note that Anaerobic is a good candidate to be abstract class.

Define class yoga which are Anaerobic fitness exercises. Use the following table to define the classes. The classes also have:

  • @Override public String description() returns the name of the respective classes.
Exercise Type Muscle affected
Yoga Triceps,Biceps


public class Profile

Assume the weight is in kgs, height in meters and gender is enum data type called Gender. In addition, this class must contain:

  • public Profile(int age, double height, double weight, Gender gender) A constructor which accepts the age,weight, height, and gender.
  • provide getters and setters for height , weight and gender.


public class DailyExercise

  • public DailyExercise(ArrayList exerciseList, int duration, double calorieTarget, Profile profile) A constructor which accepts the list of exercises, number of minutes to workout and the amount of calories to be burnt.
  • public DailyExercise(ArrayList exerciseList, Profile profile) A constructor which sets duration to 1 hour and calorieTarget to 500.
  • public void addExercise(Fitness ex) add a new Fitness in the exerciseList.
  • public void removeExercise(Fitness ex) removes an Exercise from the exerciseList.If the exercise does not exist, it will leave the exerciseList unchanged.
  • public void setExerciseList(ArrayList list) A setter method which sets the exerciseList of the DailyExercise.
  • public void setDuration(int duration) A setter method which sets the duration of the DailyExercise.
  • public void setCalorieTarget(double target) A setter method which sets the amount of calorie to be burnt of the DailyExercise.
  • public void setProfile(Profile profile) A setter method which sets the profile of the user.
  • public ArrayList getExerciseList( ) A getter method which returns the exerciseList of the DailyExercise.
  • public int getDuration() A getter method which returns the duration of the DailyExercise.
  • public double getCalorieTarget() A getter method which returns the amount of calorie to be burnt of the DailyExercise.
  • public Profile getProfile() A getter method which returns the profile of the user.
  • public Fitness[] getExercises(Muscle[] targetMuscle) - returns an array of Fitness exercises from the exerciseList that fullfills all the target muscle groups (targetMuscle) the user wants to work on for that specific day. The method will return null if there is no exercise that targets all the muscle groups.

public class WeeklyExercise

  • public WeeklyExercise(ArrayList exerciseList, int days, double weeklyCalorieTarget, Profile profile) A constructor which accepts the list of daily exercises, number of days to workout per week and the amount of calories to be burnt.
  • public WeeklyExercise(ArrayList exerciseList, Profile profile) A constructor which sets number of days to 7 and weeklyCaloryTarget to 3500.
  • public void addExercise(Fitness ex) add a Fitness in the exerciseList.
  • public void removeExercise(Fitness ex) removes a Fitness from the exerciseList.If the fitness does not exist, it will leave the exerciseList unchanged.
  • public void setExerciseList(ArrayList list) . A setter method which sets the exerciseList of the WeeklyExercise.
  • public void setDays(int days) A setter method which sets the number of days the user plans to workout for the week.
  • public void setWeeklyCalorieTarget(double target) A setter method which sets the amount of calorie to be burnt per week.
  • public void setProfile(Profile profile) A setter method which sets the user's profile.
  • public ArrayList getExerciseList( ) A getter method which returns the exerciseList of the WeeklyExercise.
  • public int getDays() A getter method which returns the number of days the user plans to workout per week.
  • public Profile getProfile() A getter method which returns the user's profile.
  • public double getWeeklyCalorieTarget() A getter method which returns the amount of calorie to be burnt for the week.
  • public ArrayListgetWeeklyExercises(Intensity intensity) a method that returns a list of DailyExercises that the user should do in order to meet the targeted calorie loss. The method evenly distributes the calorie loss over the number of days the user plans to workout. This method accepts the intensity of the exercises.
  • public ArrayListgetWeeklyExercises() a method that returns a list of DailyExercises that the user should do in order to meet the targeted calorie loss. Note that the DailyExercise suggessions include the duration (minutes) the user should work out towards the targeted calorie loss.
  • public String targetedCalorieLoss(double targetWeight, int withInDays) this method returns the string that contains a suggestion on how to loss the targeted weight within the specified number of days. . If the target weight is greater than the actual weight of the user, the method throws a TargetWeighException. You need to define a TargetWeightException that extends Java's Exception class and displays the string "Only works to lose weight".

Solutions

Expert Solution

import java.io.ObjectInputStream.GetField;

import java.util.ArrayList;

import java.util.Iterator;

import java.util.List;

public class DailyExercise {

ArrayList<Fitness> exerciseList = new ArrayList<Fitness>();

public DailyExercise(ArrayList<Fitness> exerciseList) {

this.exerciseList = exerciseList;

}

public void addExercise(Fitness ex) {

this.exerciseList.add(ex);

}

public void removeExercise(Fitness ex) {

if (this.exerciseList.contains(ex)) {

Iterator<Fitness> itr = this.exerciseList.iterator();

while (itr.hasNext()) {

Fitness fit = itr.next();

if (fit.equals(ex)) {

itr.remove();

}

}

}

}

public Fitness[] getExercises(Muscle[] targetMuscle) {

Fitness[] fit = new Fitness[1];

WeightLifting we = new WeightLifting();

if (isSubset(we.muscleTargeted(), targetMuscle, we.muscleTargeted().length, targetMuscle.length)) {

fit[0] = we;

}

if (fit[0] != null)

return fit;

else

return null;

}

public boolean isSubset(Muscle arr1[], Muscle arr2[], int m, int n) {

int i = 0;

int j = 0;

for (i = 0; i < n; i++) {

for (j = 0; j < m; j++)

if (arr2[i] == arr1[j])

break;

if (j == m)

return false;

}

return true;

}

public ArrayList<Fitness> getExerciseList() {

return exerciseList;

}

public void setExerciseList(ArrayList<Fitness> exerciseList) {

this.exerciseList = exerciseList;

}

public static void main(String[] args) {

ArrayList<Fitness> fitArrayList = new ArrayList<Fitness>();

DailyExercise dailyExercise = new DailyExercise(fitArrayList);

Fitness fit = new WeightLifting();

dailyExercise.addExercise(fit);

Muscle[] mus = new Muscle[1];

mus[0] = Muscle.Shoulders;

Fitness[] fitnessArray = dailyExercise.getExercises(mus);

if (fitnessArray != null) {

System.out.println(fitnessArray[0].description());

}

}

}

package com.exercise;

public interface Fitness {

public Muscle[] muscleTargeted();

public String description();

}

package com.exercise;

public abstract class Anaerobic implements Fitness {

@Override

public String description() {

// TODO Auto-generated method stub

return "without oxygen";

}

}

package com.exercise;

public enum Muscle {

Abs,Back,Biceps,Chest,Arms,Glutes,Shoulders,Triceps,Legs,Cardio

}

package com.exercise;

public class WeightLifting extends Anaerobic {

@Override

public Muscle[] muscleTargeted() {

Muscle[] musc= new Muscle[4];

musc[0]=Muscle.Shoulders;

musc[1]=Muscle.Legs;

musc[2]=Muscle.Arms;

musc[3]=Muscle.Triceps;

return musc;

}

@Override

public String description() {

// TODO Auto-generated method stub

return "WeightLifting";

}

}


Related Solutions

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 . Implement the basics of Fitness and types of Fitness: Aerobic. 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...
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...
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...
In Java, please write a tester code. Here's my code: public class Bicycle {     public...
In Java, please write a tester code. Here's my code: public class Bicycle {     public int cadence; public int gear;   public int speed;     public Bicycle(int startCadence, int startSpeed, int startGear) {         gear = startGear;   cadence = startCadence; speed = startSpeed;     }     public void setCadence(int newValue) {         cadence = newValue;     }     public void setGear(int newValue) {         gear = newValue;     }     public void applyBrake(int decrement) {         speed -= decrement;    ...
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;...
please write the java code so it can run on jGRASP Thanks! 1 /** 2 *...
please write the java code so it can run on jGRASP Thanks! 1 /** 2 * PassArray 3 * @Sherri Vaseashta 4 * @Version 1 5 * @see 6 */ 7 import java.util.Scanner; 8 9 /** 10 This program demonstrates passing an array 11 as an argument to a method 12 */13 14 public class PassArray 15 { 16 public static void main(String[] args) 17 { 18 19 final int ARRAY_SIZE = 4; //Size of the array 20 // Create...
Please write code in java ASAP and add comments too, will be really appreciated. Thanks CSCI203/CSCI803...
Please write code in java ASAP and add comments too, will be really appreciated. Thanks CSCI203/CSCI803 This assignment involves extension to the single source-single destination shortest path problem. The Program Your program should: 1. Read the name of a text file from the console. (Not the command line) 2. Read an undirected graph from the file. 3. Find the shortest path between the start and goal vertices specified in the file. 4. Print out the vertices on the path, in...
JAVA write a code for Task 1 and Task 2 and pass the test cases. Imagine...
JAVA write a code for Task 1 and Task 2 and pass the test cases. Imagine you have a rotary combination lock with many dials. Each dial has the digits 0 - 9. At any point in time, one digit from each dial is visible. Each dial can be rotated up or down. For some dial, if a 4 is currently visible then rotating the dial up would make 5 visible; rotating the dial down would make 3 visible. When...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT