In: Computer Science
Please write code in java and comment. Thanks. I would appreciate that.
Fitness Task:
public interface Fitness
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:
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 class DailyExercise
public class WeeklyExercise
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";
}
}