I have slight problems in understanding two little tasks. I try to be specific as I can but I have to translate everything from German, so keep this please in mind. The task is to program a sort of "training-game" where you can build training-sessions and so on. My first task is to implement an interface which is filled with three different methods:
- void setCaloryGoal (int caloryGoal) -> sets the caloryGoal
- int getCaloryGoal -> returns the caloryGoal
- double getAchievementDegree -> returns the achievementdegree (burnedcalories / caloryGoal)
Than we have to implement a new class TrainingsessionWithGoal where you use the constructor of the superclass Trainingsession but you have to add the caloryGoal and I have no idea, how I can implement it from the interface (I am sure, that we have to implement it with the set-method. My current code is this:
public TrainingsessionWithGoal(int trainingtime, Fitnessdevice fitnessdevice, int day, int month, int year, int hh, int mm, int caloryGoal) {
super(trainingtime, fitnessdevice, day, month, year, hh, mm);
this.caloryGoal = caloryGoal;
}
This totally works, but I am pretty sure, that the way I implemented the caloryGoal is not the correct way, because I never use the set-method from the interface. Does anyone have an idea for that?
In the other task, we have to create a new class TrainingProgramm in which we implement an arraylist which is filled with different objects of the class Trainingsession and the new class TrainingsessionWithGoal) and there I have absolutely no idea how to process. I googled everything but couldnt find something that helps me.
This is what I have so far:
private ArrayList <Objects> list = new ArrayList <Objects> ();
public TrainingProgramm (String programmName, ArrayList<Objects> list) {
this.programmName = programmName;
this.list = list;
}
but that obviously doesnt work. It would be very helpful if someone can guide me to the right way.
Trainingsessionalready implement that interface? If not, thenTrainingsessionWithGoalmust be declared as implementing that interface, which will force you to implement those three methods. That could be the place to start.this.kalorienZiel = kalorienZiel;should actually bethis.caloryGoal = caloryGoal;caloryGoalis notfinalinTrainingsessionWithGoalthe user of your class can still use the setter to change the value ofcaloryGoal