我有以下两个班级。我需要在第二个类中实现一个方法,即addDiscount,它将DiscountData作为输入存储在订阅对象中。
我猜我需要在这里使用arraylist?如果是这样,怎么样?
DiscountData类:
class DiscountData {
private int value;
private int length;
public DiscountData(int value, int length) {
this.value = value;
this.length = length;
}
public int getValue() {
return this.value;
}
public void setValue(int value) {
this.value = value;
}
public int getLength() {
return this.length;
}
public void setLength(int length) {
this.length = length;
}
}
订阅类:
public class Subscription {
public void addDiscount(DiscountData discountData) {
// your code here
}
}
答案 0 :(得分:0)
public class Subscription {
private List<DiscountData> data = new ArrayList<DiscountData>();
public void addDiscount(DiscountData discountData) {
data.add(discountData);
}
}