【发布时间】:2018-04-30 23:18:33
【问题描述】:
由于我是 Java 初学者,所以我有很多问题。对于我的大学,我必须编写一个健身应用程序。我们有一些提示,但大部分代码将由我们创建。任务的制定有点糊涂,因此,我在解决任务时遇到了一些问题。但是现在,我想告诉你,我必须做什么。 我必须使用此属性设置一个“健身器材”类:
- 姓名
- 类型
- 受过训练的肌肉群(另一类)
- max.trainingduration
- 每小时消耗的卡路里
除了这个属性,还有一些方法,我必须实现:
- 构造函数
- int calorieconsumption (int minutes) -> 返回给定时间内一次训练的卡路里消耗量(以分钟为单位)
- int calorieconsumption (int hours, int minutes) -> 返回给定时间(小时和分钟)内一次训练的卡路里消耗
- 布尔支持(弦肌)-> 如果设备支持肌肉,则返回 true
- 布尔支持(肌肉群肌肉群) -> 如果设备支持肌肉群,则返回 true
- boolean needspower() -> 如果设备需要电源,则返回 true。
我是这样创建的:
public class Fitness-Equipment {
private String name;
private String type;
private Musclegroupe mousclegroupe;
private int max.trainingduration;
private int burnedcaloriesperhour;
boolean power;
public Fitness-Equipment(String name, String type, Musclegroupe mousclegroupe, int max.trainingduration, int burnedcaloriesperhour) {
this.name = name;
this.type = type;
this.mousclegroupe = mousclegroupe;
this.max.trainingduration = max.trainingduration;
this.burnedcaloriesperhour = burnedcaloriesperhour;
}
//Setter & Getter for all attributes above//
public int calorieconsumption (int trainingduration) {
return (burnedcaloriesperhour = trainingduration * (burnedcaloriesperhour / 60));
}
public boolean supports (String muscle) {
return (muskelgroupe.contains(muscle));
}
public boolean supports (Musclegroupe musclegroupe) {
return (this.musclegroupe.equals(musclegroupe));
}
public boolean needspower () {
return (power = true);
}
}
我是这样实现的吗?有时我不确定是否必须为我的类添加一些属性,或者这些方法是否会为我做这些。最大的问题是,任务没有很好地制定,所以我在解决它们时非常没有安全感。对不起我的英语,它不是我的母语,代码是用德语写的,所以我不得不翻译它:D
【问题讨论】:
-
您是否已经尝试编译您的代码?
-
Stackoverflow 问题询问有关“如何进行”以及您的代码是否“好”的建议,这将为您赢得负面声誉。你现在得到了通行证,因为你显然是新人。我建议您在声誉下降之前阅读 stackoverflow 如何提问页面。
标签: java class methods constructor