试试这个代码:
Descriptor.java
public class Descriptor {
private int fromAge;
private int tillAge;
private float beginner;
private float regular;
private float pro;
// CONSTRUCTORS
public Descriptor() {}
public Descriptor(int fromAge, int tillAge, float beginner, float regular, float pro) {
this.fromAge = fromAge;
this.tillAge = tillAge;
this.beginner = beginner;
this.regular = regular;
this.pro = pro;
}
// SETTER
public void setTillAge(int tillAge) {
this.tillAge = tillAge;
}
public void setFromAge(int fromAge) {
this.fromAge = fromAge;
}
public void setBeginner(float beginner) {
this.beginner = beginner;
}
public void setRegular(float regular) {
this.regular = regular;
}
public void setPro(float pro) {
this.pro = pro;
}
// GETTER
public int getTillAge() {
return tillAge;
}
public int getFromAge() {
return fromAge;
}
public float getBeginner() {
return beginner;
}
public float getRegular() {
return regular;
}
public float getPro() {
return pro;
}
}
然后,在您的活动课程中,MainActivity.java
您可以为男性声明一个结构,为女性声明另一个结构
Descriptor[] descriptorMale = {
new Descriptor(13, 19, 5f, 7f, 9f),
new Descriptor(20, 29, 6f, 13f, 16f),
new Descriptor(30, 39, 7f, 18f, 19f),
new Descriptor(40, 49, 8f, 29f, 33f),
new Descriptor(50, 59, 9f, 30f, 37f),
new Descriptor(60, 120, 10f, 41f, 44f)
};
Descriptor[] descriptorFemale = {
new Descriptor(13, 19, 5f, 7f, 9f),
new Descriptor(20, 29, 6f, 13f, 16f),
new Descriptor(30, 39, 7f, 18f, 19f),
new Descriptor(40, 49, 8f, 29f, 33f),
new Descriptor(50, 59, 9f, 30f, 37f),
new Descriptor(60, 120, 10f, 41f, 44f)
};
最后,您可以通过以下方式使用 getter/setter 方法:
descriptorMale[1].getBeginner();
descriptorFemale[3].setFromAge(18);